diff --git a/config.go b/config.go index da964a08b..e50794c2e 100644 --- a/config.go +++ b/config.go @@ -464,7 +464,9 @@ func registerFlags(flags *pflag.FlagSet, b *flagBindings) { flags.BoolVar(boolVar(&processor.ByAuthor), "by-author", false, "render the author rollup report (bus factor and last-toucher attribution over recent git history)") 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") + 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 81216d532..f6806cb1a 100644 --- a/processor/processor.go +++ b/processor/processor.go @@ -402,6 +402,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{} @@ -1079,6 +1082,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]) } @@ -1156,8 +1162,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)