Skip to content

Commit

Permalink
Use -j/--json cli flag instead of --format
Browse files Browse the repository at this point in the history
  • Loading branch information
timofurrer committed Apr 5, 2017
1 parent 6512130 commit e3e1fdf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
8 changes: 3 additions & 5 deletions docs/user-guide/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,8 @@ You can limit the report to a project or a tag using the `--project` and
`--tag` options. They can be specified several times each to add multiple
projects or tags to the report.

You can change to output format by specifing the format via `--format`.
Available formats are:
- rich (console output with human-readable formatted text)
- json (console output in json)
You can change to output format from *plaintext* to *JSON* by
using the `--json` option.

Example:

Expand Down Expand Up @@ -411,7 +409,7 @@ Flag | Help
`-d, --day` | Reports activity for the current day.
`-p, --project TEXT` | Reports activity only for the given project. You can add other projects by using this option several times.
`-T, --tag TEXT` | Reports activity only for frames containing the given tag. You can add several tags by using this option multiple times
`-f, --format [rich|json]` | Output format for the report
`-j, --json` | Format the report in JSON instead of plaintext
`--help` | Show this message and exit.

## `restart`
Expand Down
15 changes: 6 additions & 9 deletions watson/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,11 @@ def status(watson):
help="Reports activity only for frames containing the given "
"tag. You can add several tags by using this option multiple "
"times")
@click.option('-f', '--format', 'output_format', default='rich',
type=click.Choice(['rich', 'json']),
help='Output format for the report')
@click.option('-j', '--json', 'format_json', is_flag=True,
help='Format the report in JSON instead of plaintext')
@click.pass_obj
def report(watson, current, from_, to, projects,
tags, year, month, week, day, output_format):
tags, year, month, week, day, format_json):
"""
Display a report of the time spent on each project.
Expand All @@ -350,10 +349,8 @@ def report(watson, current, from_, to, projects,
`--tag` options. They can be specified several times each to add multiple
projects or tags to the report.
You can change to output format by specifing the format via `--format`.
Available formats are:
- rich (console output with human-readable formatted text)
- json (console output in json)
You can change to output format from *plaintext* to *JSON* by
using the `--json` option.
Example:
Expand Down Expand Up @@ -428,7 +425,7 @@ def report(watson, current, from_, to, projects,
except watson.WatsonError as e:
raise click.ClickException(e)

if output_format == 'json':
if format_json:
click.echo(json.dumps(report, indent=4, sort_keys=True))
else:
click.echo("{} -> {}\n".format(
Expand Down

0 comments on commit e3e1fdf

Please sign in to comment.