Skip to content
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

Merged
merged 7 commits into from
Apr 25, 2024
Merged

feat: output in config #209

merged 7 commits into from
Apr 25, 2024

Conversation

dbolson
Copy link
Contributor

@dbolson dbolson commented Apr 25, 2024

This PR has two things (please forgive me):

  1. allows saving the output flag value in the config file
  2. fixes a bug where the analytics-opt-out flag value in the config file would panic

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

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.

@@ -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)
Copy link
Contributor Author

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)
Copy link
Contributor Author

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 (
Copy link
Contributor Author

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])
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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
Copy link
Contributor Author

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ty for the tests!

@dbolson dbolson merged commit e246cbc into main Apr 25, 2024
2 checks passed
@dbolson dbolson deleted the sc-241067/output-in-config branch April 25, 2024 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants