diff --git a/config.go b/config.go index 241e507e7..419a4be71 100644 --- a/config.go +++ b/config.go @@ -458,6 +458,7 @@ func registerFlags(flags *pflag.FlagSet, b *flagBindings) { flags.IntVar(intVar(&processor.HistoryDepth), "depth", 1000, "commit window size for git history reports; 0 means entire history (large repos may be slow)") flags.BoolVar(boolVar(&processor.Timeline), "timeline", false, "render an over-time view of recent git history; with --by-author runs the author timeline, alone runs the languages timeline") flags.IntVar(intVar(&processor.HistoryBuckets), "buckets", 60, "time-bucket resolution for the git timeline reports (default 60)") + flags.BoolVar(boolVar(&processor.ExpandGlobs), "expand-globs", false, "enable glob expansion on the files or directories") // --no-fold-authors is read back via cmd.PersistentFlags().GetBool in Run, so // its bound var is irrelevant; a throwaway sink is enough in both modes. flags.BoolVar(new(bool), "no-fold-authors", false, "disable the name+email-domain identity folding fallback for git author reports (mailmap still applied)") diff --git a/processor/processor.go b/processor/processor.go index f73da0616..3d21af8e6 100644 --- a/processor/processor.go +++ b/processor/processor.go @@ -354,6 +354,9 @@ var HistoryBuckets = 60 // after the mailmap. Toggled off via --no-fold-authors. var FoldAuthors = true +// ExpandGlobs enables glob expansion on the values of [DirFilePaths]. +var ExpandGlobs = false + // DirFilePaths is not set via flags but by arguments following the flags for file or directory to process var DirFilePaths = []string{} @@ -905,6 +908,9 @@ func Process() { fmt.Fprintf(os.Stderr, "warning: --report overrides --format=%s\n", Format) } parseReportSkip(ReportSkip) + if ExpandGlobs { + fmt.Fprintf(os.Stderr, "--report takes one positional argument; globs are not expanded") + } if len(DirFilePaths) > 1 { fmt.Fprintf(os.Stderr, "warning: --report only analyses the first positional path (%s); other paths ignored\n", DirFilePaths[0]) } @@ -962,8 +968,22 @@ func Process() { filePaths := []string{} dirPaths := []string{} + allPaths := []string{} + if ExpandGlobs { + for _, pattern := range DirFilePaths { + matches, err := filepath.Glob(pattern) + if err != nil { + fmt.Fprintf(os.Stderr, "`%s` is an invalid pattern; skipping\n", pattern) + } else { + allPaths = append(allPaths, matches...) + } + } + } else { + allPaths = DirFilePaths + } + // Check if the paths or files added exist and exit if not - for _, f := range DirFilePaths { + for _, f := range allPaths { fpath := filepath.Clean(f) s, err := os.Stat(fpath)