-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Don't print response only if an empty dict/list/str #1496
Conversation
The integer 0 should be printed. This can happen from a JMESPath expression, e.g `length(something)`.
@@ -91,10 +92,11 @@ def _format_response(self, command_name, response, stream): | |||
# the response will be an empty string. We don't want to print | |||
# that out to the user but other "falsey" values like an empty | |||
# dictionary should be printed. | |||
if response: |
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.
Would it be possible to just do if response or response == 0:
, or are we worried about other types that are falsey but should show up in the output?
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.
After looking at this again, I think we can just change this to explicitly check for '{}'.
The original intent of this (years ago) was that any AWS operation that did not have an associated output shape should not generate any CLI output. In older version of the CLI, some operations could generate either an empty dict or empty string.
However, with the switchover to the normalized model parser, anytime an operation does not have an output shape, botocore gives back a dictionary that only has the RequestMetadata key populated. Once the formatter's here strip that key out, we're left with an empty dictionary.
So it should be safe to update this to only check for an empty dictionary. This meets the constraint that anything without an output shape should not generate CLI output.
Does that work for you?
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.
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.
Makes sense. By the way, will we also document this philosophy somewhere? Such as in the code as a comment paragraph?
@@ -23,6 +23,7 @@ | |||
PY3 = six.PY3 | |||
queue = six.moves.queue | |||
shlex_quote = six.moves.shlex_quote | |||
string_types = six.string_types |
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 no longer necessary
@mtdowling Feedback incorporated. |
🚢 |
The integer 0 should be printed as a result. This can happen
from a JMESPath expression, e.g
length(something)
.For example, currently:
Now you'll get:
cc @kyleknap @mtdowling @rayluo