Merge pull request #42 from opennota/files_as_params

Accept individual files as parameters
This commit is contained in:
jimt 2014-08-05 15:59:05 +02:00
commit 388b47b5ff
2 changed files with 18 additions and 10 deletions

View File

@ -151,14 +151,10 @@ func (c *Config) validate() error {
} }
for _, input := range c.Input { for _, input := range c.Input {
stat, err := os.Lstat(input.Path) _, err := os.Lstat(input.Path)
if err != nil { if err != nil {
return fmt.Errorf("Failed to stat input path '%s': %v", input.Path, err) return fmt.Errorf("Failed to stat input path '%s': %v", input.Path, err)
} }
if !stat.IsDir() {
return fmt.Errorf("Input path '%s' is not a directory.", input.Path)
}
} }
if len(c.Output) == 0 { if len(c.Output) == 0 {

View File

@ -89,16 +89,28 @@ func findFiles(dir, prefix string, recursive bool, toc *[]Asset, ignore []*regex
prefix = filepath.ToSlash(prefix) prefix = filepath.ToSlash(prefix)
} }
fd, err := os.Open(dir) fi, err := os.Stat(dir)
if err != nil { if err != nil {
return err return err
} }
defer fd.Close() var list []os.FileInfo
list, err := fd.Readdir(0) if !fi.IsDir() {
if err != nil { dir = ""
return err list = []os.FileInfo{fi}
} else {
fd, err := os.Open(dir)
if err != nil {
return err
}
defer fd.Close()
list, err = fd.Readdir(0)
if err != nil {
return err
}
} }
for _, file := range list { for _, file := range list {