Skip to content

Commit

Permalink
Colored JSON output (Azure#662)
Browse files Browse the repository at this point in the history
  • Loading branch information
derekbekoe authored Aug 8, 2016
1 parent 603d0f5 commit 81974e3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ colorama==0.3.7
jmespath
mock==1.3.0
pip
pygments==2.1.3
pylint==1.5.4
pyyaml==3.11
requests==2.9.1
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
'msrest>=0.4.0',
'msrestazure>=0.4.0',
'pip',
'pygments',
'pyyaml',
'requests',
'six',
Expand Down
5 changes: 5 additions & 0 deletions src/azure/cli/_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def format_json(obj):
return json.dumps(input_dict, indent=2, sort_keys=True, cls=ComplexEncoder,
separators=(',', ': ')) + '\n'

def format_json_color(obj):
from pygments import highlight, lexers, formatters
return highlight(format_json(obj), lexers.JsonLexer(), formatters.TerminalFormatter()) # pylint: disable=no-member

def format_table(obj):
result = obj.result
try:
Expand Down Expand Up @@ -90,6 +94,7 @@ class OutputProducer(object): #pylint: disable=too-few-public-methods

format_dict = {
'json': format_json,
'jsonc': format_json_color,
'table': format_table,
'text': format_text,
'list': format_list,
Expand Down
2 changes: 1 addition & 1 deletion src/azure/cli/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def _register_builtin_arguments(**kwargs):
global_group = kwargs['global_group']
global_group.add_argument('--subscription', dest='_subscription_id', help=argparse.SUPPRESS)
global_group.add_argument('--output', '-o', dest='_output_format',
choices=['json', 'tsv', 'list', 'table'],
choices=['json', 'tsv', 'list', 'table', 'jsonc'],
default='json',
help='Output format',
type=str.lower)
Expand Down

0 comments on commit 81974e3

Please sign in to comment.