go2idl: Allow ... pkg specs

This is closer to standard Go semantics and obsoletes our custom --recursive
flag.
This commit is contained in:
Tim Hockin
2016-06-22 15:07:24 +09:00
parent 51394e862d
commit 1ba6f5df9e
5 changed files with 35 additions and 20 deletions

View File

@@ -54,9 +54,6 @@ type GeneratorArgs struct {
// Which directories to parse.
InputDirs []string
// If true, recurse into all children of InputDirs
Recursive bool
// Source tree to write results to.
OutputBase string
@@ -89,7 +86,6 @@ func (g *GeneratorArgs) AddFlags(fs *pflag.FlagSet) {
fs.StringVarP(&g.OutputFileBaseName, "output-file-base", "O", g.OutputFileBaseName, "Base name (without .go suffix) for output files.")
fs.StringVarP(&g.GoHeaderFilePath, "go-header-file", "h", g.GoHeaderFilePath, "File containing boilerplate header text. The string YEAR will be replaced with the current 4-digit year.")
fs.BoolVar(&g.VerifyOnly, "verify-only", g.VerifyOnly, "If true, only verify existing output, do not write anything.")
fs.BoolVar(&g.Recursive, "recursive", g.VerifyOnly, "If true, recurse into all children of input directories.")
fs.StringVar(&g.GeneratedBuildTag, "build-tag", g.GeneratedBuildTag, "A Go build tag to use to identify files generated by this command. Should be unique.")
}
@@ -111,14 +107,14 @@ func (g *GeneratorArgs) NewBuilder() (*parser.Builder, error) {
b.AddBuildTags(g.GeneratedBuildTag)
for _, d := range g.InputDirs {
if g.Recursive {
if err := b.AddDirRecursive(d); err != nil {
return nil, fmt.Errorf("unable to add directory %q: %v", d, err)
}
var err error
if strings.HasSuffix(d, "/...") {
err = b.AddDirRecursive(strings.TrimSuffix(d, "/..."))
} else {
if err := b.AddDir(d); err != nil {
return nil, fmt.Errorf("unable to add directory %q: %v", d, err)
}
err = b.AddDir(d)
}
if err != nil {
return nil, fmt.Errorf("unable to add directory %q: %v", d, err)
}
}
return b, nil