Skip to content

Commit

Permalink
Don't require is_response_paginated as an arg to formatters
Browse files Browse the repository at this point in the history
Based on review feedback.
  • Loading branch information
jamesls committed Mar 16, 2015
1 parent c62dd71 commit 1ff6915
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
13 changes: 5 additions & 8 deletions awscli/clidriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions awscli/customizations/emr/emrutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
15 changes: 9 additions & 6 deletions awscli/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -52,16 +57,15 @@ 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
# (specifically colorama on windows wraps stdout).
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
Expand Down Expand Up @@ -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 = {}
Expand Down

0 comments on commit 1ff6915

Please sign in to comment.