Skip to content
This repository was archived by the owner on Aug 22, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cmd/pkger/cmds/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type packCmd struct {
*flag.FlagSet
out string
help bool
exclude slice
include slice
subs []command
}
Expand All @@ -48,6 +49,11 @@ func (e *packCmd) Exec(args []string) error {
fp := filepath.Join(info.Dir, e.out, outName)
os.RemoveAll(fp)

exclude := []string(e.exclude)
if len(exclude) > 0 {
parser.DefaultIgnoredFolders = append(parser.DefaultIgnoredFolders, exclude...)
}

decls, err := parser.Parse(info, e.include...)
if err != nil {
return err
Expand Down Expand Up @@ -104,6 +110,7 @@ func New() (*packCmd, error) {
c.FlagSet = flag.NewFlagSet("pkger", flag.ExitOnError)
c.BoolVar(&c.help, "h", false, "prints help information")
c.StringVar(&c.out, "o", "", "output directory for pkged.go")
c.Var(&c.exclude, "exclude", "folder prefix to ignore")
c.Var(&c.include, "include", "packages the specified file or directory")
c.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage:\n\n")
Expand Down
10 changes: 3 additions & 7 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/markbates/pkger/here"
)

var defaultIgnoredFolders = []string{".", "_", "vendor", "node_modules", "testdata"}
var DefaultIgnoredFolders = []string{".", "_", "vendor", "node_modules", "testdata"}

func New(her here.Info) (*Parser, error) {
return &Parser{
Expand Down Expand Up @@ -108,12 +108,8 @@ func (p *Parser) ParseDir(abs string, mode parser.Mode) ([]*ParsedSource, error)
return nil, fmt.Errorf("%s: here.Parse failed %s", err, abs)
}

filter := func(f os.FileInfo) bool {
return !f.IsDir()
}

fset := token.NewFileSet()
pkgs, err := parser.ParseDir(fset, abs, filter, 0)
pkgs, err := parser.ParseDir(fset, abs, nil, 0)
if err != nil {
return nil, fmt.Errorf("%s: ParseDir failed %s", err, abs)
}
Expand Down Expand Up @@ -200,7 +196,7 @@ func (p *Parser) parse() error {
}

base := filepath.Base(path)
for _, x := range defaultIgnoredFolders {
for _, x := range DefaultIgnoredFolders {
if strings.HasPrefix(base, x) {
return filepath.SkipDir
}
Expand Down