Skip to content
Snippets Groups Projects
Commit e2f593cf authored by Anand Gaitonde's avatar Anand Gaitonde Committed by Tom Viehman
Browse files

fix color auto detection


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: default avatarTom Viehman <tviehman@pivotal.io>
parent fb2f17e6
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......@@ -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)
}
......
......@@ -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),
)
})
......@@ -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))
......@@ -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))
......@@ -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))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment