|
9 | 9 | "strings" |
10 | 10 |
|
11 | 11 | "github.com/sinclairtarget/git-who/internal/git" |
| 12 | + "github.com/sinclairtarget/git-who/internal/pretty" |
12 | 13 | "github.com/sinclairtarget/git-who/internal/subcommands" |
13 | 14 | "github.com/sinclairtarget/git-who/internal/tally" |
14 | 15 | "github.com/sinclairtarget/git-who/internal/utils/flagutils" |
@@ -40,6 +41,7 @@ func main() { |
40 | 41 |
|
41 | 42 | versionFlag := mainFlagSet.Bool("version", false, "Print version and exit") |
42 | 43 | verboseFlag := mainFlagSet.Bool("v", false, "Enables debug logging") |
| 44 | + colorFlag := mainFlagSet.Bool("color", false, "Force enable ANSI color output (overrides NO_COLOR env var)") |
43 | 45 |
|
44 | 46 | mainFlagSet.Usage = func() { |
45 | 47 | fmt.Println("Usage: git-who [-v] [subcommand] [subcommand options...]") |
@@ -71,7 +73,7 @@ func main() { |
71 | 73 | loop: |
72 | 74 | for subcmdIndex < len(os.Args) { |
73 | 75 | switch os.Args[subcmdIndex] { |
74 | | - case "-version", "--version", "-v", "--v", "-h", "--help": |
| 76 | + case "-version", "--version", "-v", "--v", "-h", "--help", "-color", "--color": |
75 | 77 | subcmdIndex += 1 |
76 | 78 | default: |
77 | 79 | break loop |
|
85 | 87 | return |
86 | 88 | } |
87 | 89 |
|
| 90 | + // Handle color settings according to NO_COLOR spec |
| 91 | + // Priority: --color flag > NO_COLOR env var > default (enabled) |
| 92 | + if *colorFlag { |
| 93 | + pretty.SetColorEnabled(true) |
| 94 | + } else if noColor, exists := os.LookupEnv("NO_COLOR"); exists && noColor != "" { |
| 95 | + pretty.SetColorEnabled(false) |
| 96 | + } |
| 97 | + |
88 | 98 | if *verboseFlag { |
89 | 99 | configureLogging(slog.LevelDebug) |
90 | 100 | logger().Debug("log level set to DEBUG") |
|
0 commit comments