Skip to content

Commit 03c0d20

Browse files
committed
fix(core): disable colors if NO_COLOR env variable is set
1 parent 6653ea8 commit 03c0d20

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Fixed
1111
- On `server create`, mount OS disk by default on `virtio` bus. Previously default OS storage address was not explicit and varyed depending on template type.
12+
- Disable colors if user has set [NO_COLOR](https://no-color.org/) environment variable to non-empty value.
1213

1314
## [1.5.0] - 2022-07-05
1415
### Added

internal/core/core.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ func BuildRootCmd(conf *config.Config) cobra.Command {
3333
switch {
3434
case conf.GlobalFlags.ForceColours == config.True:
3535
text.EnableColors()
36-
case conf.GlobalFlags.NoColours == config.True:
36+
// Environment variable with US spelling to support https://no-color.org
37+
case conf.GlobalFlags.NoColours == config.True || os.Getenv("NO_COLOR") != "":
3738
text.DisableColors()
3839
case conf.GlobalFlags.OutputFormat != config.ValueOutputHuman:
3940
text.DisableColors()
@@ -82,22 +83,22 @@ func BuildRootCmd(conf *config.Config) cobra.Command {
8283

8384
flags := &pflag.FlagSet{}
8485
flags.StringVarP(
85-
&conf.GlobalFlags.ConfigFile, "config", "", "", "Config file",
86+
&conf.GlobalFlags.ConfigFile, "config", "", "", "Configuration file path.",
8687
)
8788
flags.StringVarP(
8889
&conf.GlobalFlags.OutputFormat, "output", "o", "human",
8990
"Output format (supported: json, yaml and human)",
9091
)
91-
config.AddToggleFlag(flags, &conf.GlobalFlags.ForceColours, "force-colours", false, "force coloured output despite detected terminal support")
92-
config.AddToggleFlag(flags, &conf.GlobalFlags.NoColours, "no-colours", false, "disable coloured output despite detected terminal support")
92+
config.AddToggleFlag(flags, &conf.GlobalFlags.ForceColours, "force-colours", false, "Force coloured output despite detected terminal support.")
93+
config.AddToggleFlag(flags, &conf.GlobalFlags.NoColours, "no-colours", false, "Disable coloured output despite detected terminal support. Colours can also be disabled by setting NO_COLOR environment variable.")
9394
flags.BoolVar(
9495
&conf.GlobalFlags.Debug, "debug", false,
95-
"Print out more verbose debug logs",
96+
"Print out more verbose debug logs.",
9697
)
9798
flags.DurationVarP(
9899
&conf.GlobalFlags.ClientTimeout, "client-timeout", "t",
99100
0,
100-
"CLI timeout when using interactive mode on some commands",
101+
"Client timeout to use in API calls.",
101102
)
102103

103104
// XXX: Apply viper value to the help as default

0 commit comments

Comments
 (0)