-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: output in config #209
Conversation
@@ -98,7 +98,12 @@ func run() func(*cobra.Command, []string) error { | |||
v.Set(key, value) | |||
} | |||
|
|||
return writeConfig(config.NewConfig(rawConfig), v, setKeyFn) | |||
configFile, err := config.NewConfig(rawConfig) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This now can return an error.
_, ok := validKinds[outputFlag] | ||
if !ok { | ||
return output.ErrInvalidOutputKind | ||
_, err := output.NewOutputKind(outputFlag) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the validation to a constructor function since it's used in a few places.
func NewConfig(rawConfig map[string]interface{}) ConfigFile { | ||
var accessToken string | ||
func NewConfig(rawConfig map[string]interface{}) (ConfigFile, error) { | ||
var ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved these to one place and added the outputKind field.
if rawConfig[cliflags.AnalyticsOptOut] != nil { | ||
stringValue := rawConfig[cliflags.AnalyticsOptOut].(string) | ||
analyticsOptOut, _ = strconv.ParseBool(stringValue) | ||
stringValue := fmt.Sprintf("%v", rawConfig[cliflags.AnalyticsOptOut]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes
panic: interface conversion: interface {} is int, not string [recovered]
for some values.
if rawConfig[cliflags.BaseURIFlag] != nil { | ||
baseURI = rawConfig[cliflags.BaseURIFlag].(string) | ||
} | ||
if rawConfig[cliflags.OutputFlag] != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This adds support to save the output flag.
@@ -8,6 +8,30 @@ import ( | |||
|
|||
var ErrInvalidOutputKind = errors.NewError("output is invalid") | |||
|
|||
type OutputKind string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add some stricter typing around this.
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNewConfig(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ty for the tests!
This PR has two things (please forgive me):
Requirements
Related issues
Provide links to any issues in this repository or elsewhere relating to this pull request.
Describe the solution you've provided
Provide a clear and concise description of what you expect to happen.
Describe alternatives you've considered
Provide a clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context about the pull request here.