Skip to content

Commit 96b8583

Browse files
committed
feat: support --color/--no-color flag and NO_COLOR env var
1 parent 4263bd2 commit 96b8583

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

jiracli/templates.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ func tmpTemplate(templateName string, data interface{}) (string, error) {
6767
}
6868

6969
func TemplateProcessor() *template.Template {
70+
noColor := len(os.Getenv("NO_COLOR")) > 0
71+
7072
funcs := map[string]interface{}{
7173
"jira": func() string {
7274
return os.Args[0]
@@ -151,6 +153,9 @@ func TemplateProcessor() *template.Template {
151153
return content
152154
},
153155
"color": func(color string) string {
156+
if noColor {
157+
return ""
158+
}
154159
return ansi.ColorCode(color)
155160
},
156161
"remLineBreak": func(content string) string {

jiracli/usage.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ func CommandLine(fig *figtree.FigTree, o *oreo.Client) *kingpin.Application {
119119
return nil
120120
}).CounterVar(&verbosity)
121121

122+
var color bool
123+
app.Flag("color", "Enable/Disable output color").PreAction(func(_ *kingpin.ParseContext) error {
124+
if color {
125+
os.Unsetenv("NO_COLOR")
126+
} else {
127+
os.Setenv("NO_COLOR", "1")
128+
}
129+
return nil
130+
}).Hidden().BoolVar(&color)
131+
122132
app.Terminate(func(status int) {
123133
for _, arg := range os.Args {
124134
if arg == "-h" || arg == "--help" || len(os.Args) == 1 {

0 commit comments

Comments
 (0)