MCPcopy Create free account
hub / github.com/bracesdev/errtrace / expandPatterns

Function expandPatterns

cmd/errtrace/main.go:254–280  ·  view source on GitHub ↗

expandPatterns turns the given list of patterns and files into a list of paths to files. Arguments that are already files are returned as-is. Arguments that are patterns are expanded using 'go list'. As a special case for stdin, "-" is returned as-is.

(args []string)

Source from the content-addressed store, hash-verified

252// Arguments that are patterns are expanded using 'go list'.
253// As a special case for stdin, "-" is returned as-is.
254func expandPatterns(args []string) ([]string, error) {
255 var files, patterns []string
256 for _, arg := range args {
257 if arg == "-" {
258 files = append(files, arg)
259 continue
260 }
261
262 if info, err := os.Stat(arg); err == nil && !info.IsDir() {
263 files = append(files, arg)
264 continue
265 }
266
267 patterns = append(patterns, arg)
268 }
269
270 if len(patterns) > 0 {
271 pkgFiles, err := goListFiles(patterns)
272 if err != nil {
273 return nil, errtrace.Wrap(fmt.Errorf("go list: %w", err))
274 }
275
276 files = append(files, pkgFiles...)
277 }
278
279 return files, nil
280}
281
282var _execCommand = exec.Command
283

Callers 2

TestExpandPatternsFunction · 0.85
RunMethod · 0.85

Calls 3

WrapFunction · 0.92
goListFilesFunction · 0.85
StatMethod · 0.65

Tested by 1

TestExpandPatternsFunction · 0.68