Skip to content

Commit

Permalink
fix color auto detection
Browse files Browse the repository at this point in the history
If nothing is set OR if there's an error reading the color value, the
CLI should autodetect based off of the TTY.

[Finishes #156326872]

Signed-off-by: Tom Viehman <tviehman@pivotal.io>
  • Loading branch information
XenoPhex authored and tjvman committed Mar 30, 2018
1 parent fb2f17e commit e2f593c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions util/configv3/color.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type ColorSetting int
// ColorEnabled returns the color setting based off:
// 1. The $CF_COLOR environment variable if set (0/1/t/f/true/false)
// 2. The 'ColorEnabled' value in the .cf/config.json if set
// 3. Defaults to ColorEnabled if nothing is set
// 3. Defaults to ColorAuto if nothing is set
func (config *Config) ColorEnabled() ColorSetting {
if config.ENV.CFColor != "" {
val, err := strconv.ParseBool(config.ENV.CFColor)
Expand All @@ -35,7 +35,7 @@ func (config *Config) ColorEnabled() ColorSetting {

val, err := strconv.ParseBool(config.ConfigFile.ColorEnabled)
if err != nil {
return ColorEnabled
return ColorAuto
}
return config.boolToColorSetting(val)
}
Expand Down
2 changes: 1 addition & 1 deletion util/configv3/color_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ var _ = Describe("Config", func() {
Entry("config=false env=unset disabled", "false", "", ColorDisabled),
Entry("config=true env=unset disabled", "true", "", ColorEnabled),

Entry("config=unset env=unset falls back to default", "", "", ColorEnabled),
Entry("config=unset env=unset falls back to default", "", "", ColorAuto),
)
})
6 changes: 3 additions & 3 deletions util/configv3/load_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var _ = Describe("Config", func() {
Expect(config).ToNot(BeNil())
Expect(config.Target()).To(Equal(DefaultTarget))
Expect(config.SkipSSLValidation()).To(BeFalse())
Expect(config.ColorEnabled()).To(Equal(ColorEnabled))
Expect(config.ColorEnabled()).To(Equal(ColorAuto))
Expect(config.PluginHome()).To(Equal(filepath.Join(homeDir, ".cf", "plugins")))
Expect(config.StagingTimeout()).To(Equal(DefaultStagingTimeout))
Expect(config.StartupTimeout()).To(Equal(DefaultStartupTimeout))
Expand Down Expand Up @@ -128,7 +128,7 @@ var _ = Describe("Config", func() {
Expect(config).ToNot(BeNil())
Expect(config.Target()).To(Equal(DefaultTarget))
Expect(config.SkipSSLValidation()).To(BeFalse())
Expect(config.ColorEnabled()).To(Equal(ColorEnabled))
Expect(config.ColorEnabled()).To(Equal(ColorAuto))
Expect(config.PluginHome()).To(Equal(filepath.Join(homeDir, ".cf", "plugins")))
Expect(config.StagingTimeout()).To(Equal(DefaultStagingTimeout))
Expect(config.StartupTimeout()).To(Equal(DefaultStartupTimeout))
Expand Down Expand Up @@ -203,7 +203,7 @@ var _ = Describe("Config", func() {
Expect(config).ToNot(BeNil())
Expect(config.Target()).To(Equal(DefaultTarget))
Expect(config.SkipSSLValidation()).To(BeFalse())
Expect(config.ColorEnabled()).To(Equal(ColorEnabled))
Expect(config.ColorEnabled()).To(Equal(ColorAuto))
Expect(config.PluginHome()).To(Equal(filepath.Join(homeDir, ".cf", "plugins")))
Expect(config.StagingTimeout()).To(Equal(DefaultStagingTimeout))
Expect(config.StartupTimeout()).To(Equal(DefaultStartupTimeout))
Expand Down

0 comments on commit e2f593c

Please sign in to comment.