add support for converting multiple directories simultaneously

This commit is contained in:
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
// well as whether to recursively process assets in any sub directories.
Input InputConfig
Input []InputConfig
// Output defines the output file for the generated code.
// 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")
}
stat, err := os.Lstat(c.Input.Path)
for _, input := range c.Input {
stat, err := os.Lstat(input.Path)
if err != nil {
return fmt.Errorf("Input path: %v", err)
return fmt.Errorf("Failed to stat input path '%s': %v", input.Path, err)
}
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 {
@ -158,7 +160,7 @@ func (c *Config) validate() error {
c.Output = filepath.Join(cwd, "bindata.go")
}
stat, err = os.Lstat(c.Output)
stat, err := os.Lstat(c.Output)
if err != nil {
if !os.IsNotExist(err) {
return fmt.Errorf("Output path: %v", err)

View File

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

View File

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