Add --json flag for resource-class cmds #1088
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Relates to #380
Checklist
=========
Internal Checklist
Not applicable to me, a non-CircleCI employee
Changes
=======
Implementation
I implemented my changes in the following way:
--json
flag to theresource_class.go
file where it was appropriate to, for thecreate
andlist
command actions.--json
flag was set on the command line, and if so, we Marshal the appropriate object and set it in the Writer interface offered by the cobracmd
object.circleci runner resource-class list <>
circleci runner resource-class create <>
they will behave exactly as they did. Only if you include a
--json
flag will you see new behavior, returned to stdout.Automated Tests
I made sure to add tests in
resource_class_test.go
where appropriate as well as update the expected usage files.Manual Tests
I executed the following commands manually (alongside the automated testing), to ensure:
Rationale
=========
Background
In my position at Okta, a CircleCI customer, I have a few automation tasks that require the use of the
circleci runner resource-class list
andcircleci runner resource-class create
commands, where I specifically need to grab the output of these commands and do subsequent actions. As a result, my motivation for adding the--json
flag support for thecircleci runner resource-class
command is to return more easily parsable output, instead of the default ASCII table format.Potential Future Work
If this PR is accepted, and it is deemed advantageous, I can move this new
--json
flag to be global/applicable so that other CLI commands can return JSON formatted responses to stdout.