-
Notifications
You must be signed in to change notification settings - Fork 886
feat: add JSON output format to many CLI commands #6082
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
Conversation
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 is awesome! One nice addition would be to have a golden file test for the JSON output for one or multiple commands. It might help us make sure we don't have any regressions when messing with struct tags.
I feel I have to mention the panics though.. I know why they're there, I just don't like them. 😂 (Won't ask for a change this time around. 😉)
I've added golden files for Regarding panics, it'd be awkward to return an error from the new outputter function as this func is called from within a new command function, which does not return an error. |
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.
Nice solution for golden files! ❤️
replace[k] = []byte(v) | ||
} | ||
for k, v := range replace { | ||
got = bytes.ReplaceAll(got, []byte(k), v) |
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.
Maybe we can just use a map[string]string
and strings.ReplaceAll
to simplify and avoid the byte/string conversions?
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.
We'd have to convert got
to a string in that case:
gotStr := strings.ReplaceAll([]byte(got), k, v)
got = []byte(gotStr)
Reworks the output format code which is scattered across many commands into a consistent output formatter object, which handles applying flags and the final output operation.
The output formatter provides an interface for making custom formatters (which some commands utilize, e.g.
coder user show
).Some commands do some messy stuff currently as they run extra code before formatting, which I've accommodated for by reusing the existing functions to avoid breaking existing output formatting.