Skip to content

Commit

Permalink
Support globbing dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
dor-utila committed Nov 30, 2022
1 parent fd9c44c commit 900e8e6
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions cmd/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ func expandCopyCmd(ef *earthfile.Earthfile, cp earthfile.CopyCmd) (res []string,
if err != nil {
return nil, fmt.Errorf("could not glob pattern '%s' in '%s': %w", cp.From, ef.Dir, err)
}
res, err = expandGlobMatches(res)
if err != nil {
return nil, fmt.Errorf("could not expand glob matches in '%s': %w", ef.Dir, err)
}
} else if fileutil.DirExistsBestEffort(fsFrom) {
res, err = filesInDir(fsFrom)
if err != nil {
Expand All @@ -119,6 +123,25 @@ func expandCopyCmd(ef *earthfile.Earthfile, cp earthfile.CopyCmd) (res []string,
return res, nil
}

func expandGlobMatches(matches []string) ([]string, error) {
res := make([]string, 0, len(matches))
for _, m := range matches {
if !fileutil.DirExistsBestEffort(m) {
res = append(res, m)
continue
}

logger.DebugPrintf("Expanding files in dir %s", m)
files, err := filesInDir(m)
if err != nil {
return nil, err
}

res = append(res, files...)
}
return res, nil
}

// '+src/bla' -> 'src', 'bla'
func splitTargetFileSelector(path string) (target, selector string) {
plusPos := strings.IndexRune(path, '+')
Expand Down

0 comments on commit 900e8e6

Please # to comment.