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)
| 252 | // Arguments that are patterns are expanded using 'go list'. |
| 253 | // As a special case for stdin, "-" is returned as-is. |
| 254 | func 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 | |
| 282 | var _execCommand = exec.Command |
| 283 |