Review changes

Signed-off-by: Chris Mark <chrismarkou92@gmail.com>
This commit is contained in:
Chris Mark
2019-02-18 09:28:04 +02:00
parent f5f8e49fa3
commit 77eebb89fd
2 changed files with 30 additions and 10 deletions

View File

@@ -54,12 +54,28 @@ func (a *flagsAndArgs) Validate(args []string) error {
return nil
}
// ExpandFileSource normalizes a string list, possibly
// containing globs, into a validated, globless list.
// For example, this list:
// some/path
// some/dir/a*
// bfile=some/dir/b*
// becomes:
// some/path
// some/dir/airplane
// some/dir/ant
// some/dir/apple
// bfile=some/dir/banana
// i.e. everything is converted to a key=value pair,
// where the value is always a relative file path,
// and the key, if missing, is the same as the value.
// In the case where the key is explicitly declared,
// the globbing, if present, must have exactly one match.
func (a *flagsAndArgs) ExpandFileSource(fSys fs.FileSystem) error {
var results []string
var key string
for _, pattern := range a.FileSources {
var patterns []string
key = ""
key := ""
// check if the pattern is in `--from-file=[key=]source` format
// and if so split it to send only the file-pattern to glob function
s := strings.Split(pattern, "=")
@@ -77,8 +93,8 @@ func (a *flagsAndArgs) ExpandFileSource(fSys fs.FileSystem) error {
// and extend it with the `key=` prefix
if key != "" {
if len(result) != 1 {
msg := fmt.Sprintf("%s pattern should not catch more than one file", pattern)
return fmt.Errorf(msg)
return fmt.Errorf(
"'pattern '%s' catches files %v, should catch only one.", pattern, result)
}
fileSource := fmt.Sprintf("%s=%s", key, result[0])
results = append(results, fileSource)