Skip to content

Commit

Permalink
Add json output option
Browse files Browse the repository at this point in the history
  • Loading branch information
egegunes committed Jun 15, 2019
1 parent 7c0f0c6 commit 08169ac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions redmine/cli/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from collections import OrderedDict

import click
Expand Down Expand Up @@ -56,6 +57,7 @@ def cli(ctx, cfg, **kwargs):
@click.option(OPTIONS["created-on"]["long"], default=None)
@click.option(OPTIONS["created-after"]["long"], default=None)
@click.option(OPTIONS["created-before"]["long"], default=None)
@click.option(OPTIONS["json"]["long"], default=False, show_default=True)
@click.pass_obj
@click.pass_context
def issues(ctx, redmine, issue_ids, **kwargs):
Expand All @@ -72,6 +74,9 @@ def issues(ctx, redmine, issue_ids, **kwargs):
except HTTPError as e:
return click.echo(click.style(f"Fatal: {e}", fg="red"))

if kwargs.get("json"):
return click.echo(json.dumps(issues))

for issue in issues:
click.echo(Issue(**issue).as_row())

Expand Down
1 change: 1 addition & 0 deletions redmine/cli/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
"journals": {"long": "--journals/--no-journals", "short": "-j/-J"},
"edit": {"long": "--edit/--no-edit", "short": "-e/-E"},
"force": {"long": "--force/--no-force", "help": "Invalidate cache"},
"json": {"long": "--json/--no-json"},
}

0 comments on commit 08169ac

Please sign in to comment.