Add --json flag for resource-class cmds #1088
Draft
+117
−15
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.
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.Tests
I made sure to add tests in
resource_class_test.go
where appropriate as well as update the[create-expected-usage.txt](https://github.com/CircleCI-Public/circleci-cli/compare/develop...jdelnano:circleci-cli:add-json-output-flag-for-resource-class-cmds?expand=1#diff-694751a2b7d7a982b3a13b6bcb00d307f3e25dc7014c17520056d3d3c1dbd8ca)
file.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.Manual Testing
I executed the following commands manually (alongside the automated testing), to ensure:
Screenshots
============
Before
Image or [gif](https://giphy.com/apps/giphycapture)After
Image or gif where change can be clearly seenHere are some helpful tips you can follow when submitting a pull request:
main
.make build
in the repository root.make test
).--debug
flag is often helpful for debugging HTTP client requests and responses.make lint
). Note: This requires Docker to run inside a local job.