Skip to content

Commit

Permalink
fix: Read boolean config from file
Browse files Browse the repository at this point in the history
  • Loading branch information
achannarasappa committed Jan 31, 2021
1 parent 0ccfa7b commit f8d1f4e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
9 changes: 4 additions & 5 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,10 @@ func read(fs afero.Fs, options Options, configFile *Config) (Config, error) {
if len(*options.Watchlist) != 0 {
config.Watchlist = strings.Split(strings.ReplaceAll(*options.Watchlist, " ", ""), ",")
}

config.RefreshInterval = getRefreshInterval(*options.RefreshInterval, configFile.RefreshInterval)
config.Separate = getBoolOption(*options.Separate, configFile.Separate)
config.ExtraInfoExchange = getBoolOption(*options.ExtraInfoExchange, configFile.ExtraInfoExchange)
config.ExtraInfoFundamentals = getBoolOption(*options.ExtraInfoFundamentals, configFile.ExtraInfoFundamentals)
config.RefreshInterval = getRefreshInterval(*options.RefreshInterval, config.RefreshInterval)
config.Separate = getBoolOption(*options.Separate, config.Separate)
config.ExtraInfoExchange = getBoolOption(*options.ExtraInfoExchange, config.ExtraInfoExchange)
config.ExtraInfoFundamentals = getBoolOption(*options.ExtraInfoFundamentals, config.ExtraInfoFundamentals)

return config, err

Expand Down
30 changes: 19 additions & 11 deletions internal/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,18 @@ var _ = Describe("Cli", func() {
When("the config file also has a refresh interval defined", func() {
It("should set the refresh interval from the cli argument", func() {
refreshInterval = 8
config.RefreshInterval = 7
configPath = ".ticker.yaml"
afero.WriteFile(fs, ".ticker.yaml", []byte("interval: 7"), 0644)
Validate(&config, fs, options)(&cobra.Command{}, []string{})
Expect(config.RefreshInterval).To(Equal(8))
})
})
})

When("refresh interval is set in the config file", func() {
It("should set the config to the cli argument value", func() {
config.RefreshInterval = 357
It("should set the config to the config argument value", func() {
configPath = ".ticker.yaml"
afero.WriteFile(fs, ".ticker.yaml", []byte("interval: 357"), 0644)
Validate(&config, fs, options)(&cobra.Command{}, []string{})
Expect(config.RefreshInterval).To(Equal(357))
})
Expand All @@ -210,16 +212,18 @@ var _ = Describe("Cli", func() {
When("the config file also has a separate flag defined", func() {
It("should set the separate flag from the cli argument", func() {
separate = true
config.Separate = false
configPath = ".ticker.yaml"
afero.WriteFile(fs, ".ticker.yaml", []byte("separate: true"), 0644)
Validate(&config, fs, options)(&cobra.Command{}, []string{})
Expect(config.Separate).To(Equal(true))
})
})
})

When("separate flag is set in the config file", func() {
It("should set the config to the cli argument value", func() {
config.Separate = true
It("should set the config to the config argument value", func() {
configPath = ".ticker.yaml"
afero.WriteFile(fs, ".ticker.yaml", []byte("separate: true"), 0644)
Validate(&config, fs, options)(&cobra.Command{}, []string{})
Expect(config.Separate).To(Equal(true))
})
Expand All @@ -244,16 +248,18 @@ var _ = Describe("Cli", func() {
When("the config file also has a extra-info-exchange flag defined", func() {
It("should set the extra-info-exchange flag from the cli argument", func() {
extraInfoExchange = true
config.ExtraInfoExchange = false
configPath = ".ticker.yaml"
afero.WriteFile(fs, ".ticker.yaml", []byte("extra-info-exchange: false"), 0644)
Validate(&config, fs, options)(&cobra.Command{}, []string{})
Expect(config.ExtraInfoExchange).To(Equal(true))
})
})
})

When("extra-info-exchange flag is set in the config file", func() {
It("should set the config to the cli argument value", func() {
config.ExtraInfoExchange = true
It("should set the config to the config argument value", func() {
configPath = ".ticker.yaml"
afero.WriteFile(fs, ".ticker.yaml", []byte("extra-info-exchange: true"), 0644)
Validate(&config, fs, options)(&cobra.Command{}, []string{})
Expect(config.ExtraInfoExchange).To(Equal(true))
})
Expand All @@ -278,7 +284,8 @@ var _ = Describe("Cli", func() {
When("the config file also has a extra-info-fundamentals flag defined", func() {
It("should set the extra-info-fundamentals flag from the cli argument", func() {
extraInfoFundamentals = true
config.ExtraInfoFundamentals = false
configPath = ".ticker.yaml"
afero.WriteFile(fs, ".ticker.yaml", []byte("extra-info-fundamentals: false"), 0644)
Validate(&config, fs, options)(&cobra.Command{}, []string{})
Expect(config.ExtraInfoFundamentals).To(Equal(true))
})
Expand All @@ -287,7 +294,8 @@ var _ = Describe("Cli", func() {

When("extra-info-fundamentals flag is set in the config file", func() {
It("should set the config to the cli argument value", func() {
config.ExtraInfoFundamentals = true
configPath = ".ticker.yaml"
afero.WriteFile(fs, ".ticker.yaml", []byte("extra-info-fundamentals: true"), 0644)
Validate(&config, fs, options)(&cobra.Command{}, []string{})
Expect(config.ExtraInfoFundamentals).To(Equal(true))
})
Expand Down

0 comments on commit f8d1f4e

Please sign in to comment.