add support for converting multiple directories simultaneously

pull/4/head
Alan Shreve 2013-11-08 17:21:11 +02:00
parent 2c7ab48825
commit 7ab45c816f
3 changed files with 16 additions and 12 deletions

View File

@ -34,7 +34,7 @@ type Config struct {
// Input defines the directory path, containing all asset files as // Input defines the directory path, containing all asset files as
// well as whether to recursively process assets in any sub directories. // well as whether to recursively process assets in any sub directories.
Input InputConfig Input []InputConfig
// Output defines the output file for the generated code. // Output defines the output file for the generated code.
// If left empty, this defaults to 'bindata.go' in the current // If left empty, this defaults to 'bindata.go' in the current
@ -140,13 +140,15 @@ func (c *Config) validate() error {
return fmt.Errorf("Missing package name") return fmt.Errorf("Missing package name")
} }
stat, err := os.Lstat(c.Input.Path) for _, input := range c.Input {
if err != nil { stat, err := os.Lstat(input.Path)
return fmt.Errorf("Input path: %v", err) if err != nil {
} return fmt.Errorf("Failed to stat input path '%s': %v", input.Path, err)
}
if !stat.IsDir() { if !stat.IsDir() {
return fmt.Errorf("Input path is not a directory.") return fmt.Errorf("Input path '%s' is not a directory.", input.Path)
}
} }
if len(c.Output) == 0 { if len(c.Output) == 0 {
@ -158,7 +160,7 @@ func (c *Config) validate() error {
c.Output = filepath.Join(cwd, "bindata.go") c.Output = filepath.Join(cwd, "bindata.go")
} }
stat, err = os.Lstat(c.Output) stat, err := os.Lstat(c.Output)
if err != nil { if err != nil {
if !os.IsNotExist(err) { if !os.IsNotExist(err) {
return fmt.Errorf("Output path: %v", err) return fmt.Errorf("Output path: %v", err)

View File

@ -26,9 +26,11 @@ func Translate(c *Config) error {
} }
// Locate all the assets. // Locate all the assets.
err = findFiles(c.Input.Path, c.Prefix, c.Input.Recursive, &toc) for _, input := range c.Input {
if err != nil { err = findFiles(input.Path, c.Prefix, input.Recursive, &toc)
return err if err != nil {
return err
}
} }
// Create output file. // Create output file.

View File

@ -60,7 +60,7 @@ func parseArgs() *bindata.Config {
input := filepath.Clean(flag.Arg(0)) input := filepath.Clean(flag.Arg(0))
c.Input = parseInput(input) c.Input = []bindata.InputConfig{parseInput(input)}
if flag.NArg() > 1 { if flag.NArg() > 1 {
c.Output = filepath.Clean(flag.Arg(1)) c.Output = filepath.Clean(flag.Arg(1))
} }