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 flag config cmd #202

Merged

Conversation

dbolson
Copy link
Contributor

@dbolson dbolson commented Apr 23, 2024

Supports plain text and JSON output for the config --list command.

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.

@@ -68,7 +68,7 @@ func runGet(

output, err := output.CmdOutput(
viper.GetString(cliflags.OutputFlag),
output.NewSingularOutputterFn(response),
output.NewSingularOutput(response),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed these functions to be simpler to read.

}

// New unmarshals a single config resource and wires up a particular plain text output function.
func (o configOutputterFn) New() (Outputter, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

By making the output API simpler for the caller, we're forced to implement a new New() method in addition to a new PlaintextOutputFn type. If we find the tradeoff not worth it, we can reconsider.

return SingularOutputter{}, err
}

return SingularOutputter{
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 was able to reuse this type since it's a singular resource but a different way to format.

@@ -23,14 +23,12 @@ type OutputterFn interface {
}

// PlaintextOutputFn represents the various ways to output a resource or resources.
type PlaintextOutputFn func(resource) string
type PlaintextOutputFn[T any] func(t T) 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.

Now this can take different resource types.

* Add plain text error handling

* Output flag errors as plain text or JSON

* Remove unused code

* Update all commands to return plaintext or JSON

* Refactor outputter

* Backfill tests

* Reorganize

* Refactor

* Remove comments

* Renamed functions
@dbolson dbolson merged commit 5de73ec into sc-241065/output-flag-all-endpoints Apr 24, 2024
1 check passed
@dbolson dbolson deleted the sc-241065/output-flag-config-cmd branch April 24, 2024 21:31
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