Skip to content

Commit

Permalink
Move decapodcli to no-pager by default
Browse files Browse the repository at this point in the history
  • Loading branch information
9seconds committed Nov 23, 2016
1 parent 765289e commit 483b76d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
6 changes: 4 additions & 2 deletions decapodcli/decapodcli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

import warnings

import click

# This is done to suppress Click warnings about unicode
warnings.simplefilter("ignore")

click.disable_unicode_literals_warning = True
warnings.simplefilter("always", PendingDeprecationWarning)


from decapodcli import cloud_config # NOQA
Expand Down
6 changes: 3 additions & 3 deletions decapodcli/decapodcli/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def log(ctx, execution_id, client):
response = client.get_execution_log(execution_id,
headers={"Content-Type": "text/plain"})

if ctx.obj["no_pager"]:
click.echo(response)
else:
if ctx.obj["pager"]:
click.echo_via_pager(response)
else:
click.echo(response)
28 changes: 25 additions & 3 deletions decapodcli/decapodcli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from __future__ import absolute_import
from __future__ import unicode_literals

import warnings

import click

from decapodcli import decorators
Expand Down Expand Up @@ -79,6 +81,12 @@
envvar="DECAPOD_NO_PAGER",
help="Do not use pager for output."
)
@click.option(
"--pager", "-r",
envvar="DECAPOD_PAGER",
is_flag=True,
help="Use pager for output."
)
@click.option(
"--output-format", "-f",
default="json",
Expand All @@ -87,7 +95,7 @@
)
@click.pass_context
def cli(ctx, url, login, password, no_verify, ssl_certificate, debug,
timeout, no_pager, output_format):
timeout, no_pager, pager, output_format):
"""Decapod command line tool.
With this CLI it is possible to access all API endpoints of Decapod.
Expand All @@ -108,10 +116,24 @@ def cli(ctx, url, login, password, no_verify, ssl_certificate, debug,
- DECAPOD_SSL_CERTIFICATE - this environment variable sets a path
to SSL client certificate.
- DECAPOD_DEBUG - this environment variable sets debug mode.
- DECAPOD_NO_PAGER - this environment variable removes pager
- DECAPOD_NO_PAGER - (deprecated) this environment variable
removes pager support.
- DECAPOD_PAGER - this environment variable add pager
support.
"""

pagerize = False
if no_pager:
warnings.warn(
"--no-pager (or environment variable DECAPOD_NO_PAGER) "
"is deprecated. This is default behavior now. If you want "
"pager support, please use --pager option.",
PendingDeprecationWarning
)
pagerize = False
if pager:
pagerize = True

if ssl_certificate:
ssl_certificate.close()
ssl_certificate = ssl_certificate.name
Expand All @@ -123,7 +145,7 @@ def cli(ctx, url, login, password, no_verify, ssl_certificate, debug,
"debug": debug,
"timeout": timeout,
"format": output_format,
"no_pager": no_pager,
"pager": pagerize,
"client": decapodlib.Client(url, login, password,
timeout=timeout, verify=not no_verify,
certificate_file=ssl_certificate)
Expand Down
6 changes: 3 additions & 3 deletions decapodcli/decapodcli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ def format_output_json(ctx, response, error=False):

if error:
click.echo(response, err=True)
elif ctx.obj["no_pager"]:
click.echo(response)
else:
elif ctx.obj["pager"]:
click.echo_via_pager(response)
else:
click.echo(response)


def update_model(item_id, fetch_item, update_item, model, **kwargs):
Expand Down

0 comments on commit 483b76d

Please sign in to comment.