diff --git a/awscli/clidriver.py b/awscli/clidriver.py index 5b6e5e8e1d2e..bdde2cf02bf8 100644 --- a/awscli/clidriver.py +++ b/awscli/clidriver.py @@ -649,20 +649,17 @@ def invoke(self, service_name, operation_name, parameters, parsed_globals): py_operation_name = xform_name(operation_name) if client.can_paginate(py_operation_name) and parsed_globals.paginate: paginator = client.get_paginator(py_operation_name) - pages = paginator.paginate(**parameters) - self._display_response(operation_name, pages, True, parsed_globals) + response = paginator.paginate(**parameters) else: - response_data = getattr(client, xform_name(operation_name))( + response = getattr(client, xform_name(operation_name))( **parameters) - self._display_response( - operation_name, response_data, False, - parsed_globals) + self._display_response(operation_name, response, parsed_globals) return 0 def _display_response(self, command_name, response, - is_response_paginated, parsed_globals): + parsed_globals): output = parsed_globals.output if output is None: output = self._session.get_config_variable('output') formatter = get_formatter(output, parsed_globals) - formatter(command_name, response, is_response_paginated) + formatter(command_name, response) diff --git a/awscli/customizations/emr/emrutils.py b/awscli/customizations/emr/emrutils.py index 77141ddf3652..bd88e44f376e 100644 --- a/awscli/customizations/emr/emrutils.py +++ b/awscli/customizations/emr/emrutils.py @@ -248,5 +248,5 @@ def display_response(session, operation_name, result, parsed_globals): cli_operation_caller = CLIOperationCaller(session) # Calling a private method. Should be changed after the functionality # is moved outside CliOperationCaller. - cli_operation_caller._display_response(operation_name, result, False, - parsed_globals) + cli_operation_caller._display_response( + operation_name, result, parsed_globals) diff --git a/awscli/formatter.py b/awscli/formatter.py index eaa7c5884cd0..61cafb300651 100644 --- a/awscli/formatter.py +++ b/awscli/formatter.py @@ -15,6 +15,7 @@ from botocore.compat import json from botocore.utils import set_value_from_jmespath +from botocore.paginate import PageIterator from awscli.table import MultiTable, Styler, ColorizedStyler from awscli import text @@ -25,6 +26,10 @@ LOG = logging.getLogger(__name__) +def is_response_paginated(response): + return isinstance(response, PageIterator) + + class Formatter(object): def __init__(self, args): self._args = args @@ -52,8 +57,7 @@ def _flush_stream(self, stream): class FullyBufferedFormatter(Formatter): - def __call__(self, command_name, response, - is_response_paginated=False, stream=None): + def __call__(self, command_name, response, stream=None): if stream is None: # Retrieve stdout on invocation instead of at import time # so that if anything wraps stdout we'll pick up those changes @@ -61,7 +65,7 @@ def __call__(self, command_name, response, stream = self._get_default_stream() # I think the interfaces between non-paginated # and paginated responses can still be cleaned up. - if is_response_paginated: + if is_response_paginated(response): response_data = response.build_full_result() else: response_data = response @@ -221,12 +225,11 @@ def _group_scalar_keys(self, current): class TextFormatter(Formatter): - def __call__(self, command_name, response, - is_response_paginated=False, stream=None): + def __call__(self, command_name, response, stream=None): if stream is None: stream = self._get_default_stream() try: - if is_response_paginated: + if is_response_paginated(response): result_keys = response.result_keys for page in response: current = {}