-
Notifications
You must be signed in to change notification settings - Fork 109
kernelci.cli: add echo_json() function #2232
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
LGTM. Please fix linter errors. |
Thanks! Please don't review PRs that are not ready for review though ;) |
d77b485
to
827d33d
Compare
fede860
to
c97d0c0
Compare
Add kernelci.cli.echo_json() function as a convenience for the common use-case where some JSON data needs to be dumped on stdout. Update all subcommands accordingly to use it. This takes into account that indent=0 should mean no formatting, rather than indentation with only line returns and no spaces. Signed-off-by: Guillaume Tucker <[email protected]>
c97d0c0
to
084bea3
Compare
attributes = split_attributes(attributes) | ||
nodes = api.get_nodes(attributes, offset, limit) | ||
data = json.dumps(nodes, indent=indent) | ||
data = json.dumps(nodes, indent=indent or None) |
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.
indent
will be set to None
by default if not provided.
Also, indent=indent or None
would be evaluated to None
if user has provided 0
as indent.
data = json.dumps(nodes, indent=indent or None) | |
data = json.dumps(nodes, indent=indent) |
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.
No, I made this change on purpose as otherwise it prints the output formatted with newlines and no identation space when indent=0
. So None
is needed in this case.
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.
It's also explained in the git commit and the echo_json()
docstring.
attributes = split_attributes(attributes) | ||
users = api.get_users(attributes) | ||
data = json.dumps(users, indent=indent) | ||
data = json.dumps(users, indent=indent or None) |
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.
Same comment as above.
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.
Of course, I fixed this everywhere :) And then wrapped it up in a helper function.
With the
With just
|
But isn't it what a user expects with |
It doesn't matter what |
Makes sense. Thanks for clarifying. |
Thanks for the review :) |
Uh oh!
There was an error while loading. Please reload this page.