Revision 0399ac7e

b/kamaki/cli/commands/pithos.py
40 40
from kamaki.cli.errors import raiseCLIError, CLISyntaxError
41 41
from kamaki.cli.utils import (
42 42
    format_size, to_bytes, print_dict, print_items, pretty_keys,
43
    page_hold, bold, ask_user, get_path_size)
43
    page_hold, bold, ask_user, get_path_size, print_json)
44 44
from kamaki.cli.argument import FlagArgument, ValueArgument, IntArgument
45 45
from kamaki.cli.argument import KeyValueArgument, DateArgument
46 46
from kamaki.cli.argument import ProgressBarArgument
......
329 329
        exact_match=FlagArgument(
330 330
            'Show only objects that match exactly with path',
331 331
            '--exact-match'),
332
        enum=FlagArgument('Enumerate results', '--enumerate')
332
        enum=FlagArgument('Enumerate results', '--enumerate'),
333
        json_output=FlagArgument('show output in json', ('-j', '--json'))
333 334
    )
334 335

  
335 336
    def print_objects(self, object_list):
337
        if self['json_output']:
338
            print_json(object_list)
339
            return
336 340
        limit = int(self['limit']) if self['limit'] > 0 else len(object_list)
337 341
        for index, obj in enumerate(object_list):
338 342
            if self['exact_match'] and self.path and not (
......
362 366
                page_hold(index, limit, len(object_list))
363 367

  
364 368
    def print_containers(self, container_list):
369
        if self['json_output']:
370
            print_json(container_list)
371
            return
365 372
        limit = int(self['limit']) if self['limit'] > 0\
366 373
            else len(container_list)
367 374
        for index, container in enumerate(container_list):
b/kamaki/cli/utils.py
35 35
from re import compile as regex_compile
36 36
from time import sleep
37 37
from os import walk, path
38
from json import dumps
38 39

  
39 40
from kamaki.cli.errors import raiseCLIError
40 41

  
......
100 101
    return new_d
101 102

  
102 103

  
104
def print_json(data):
105
    """Print a list or dict as json in console
106

  
107
    :param data: json-dumpable data
108
    """
109
    print(dumps(data, indent=2))
110

  
111

  
103 112
def print_dict(
104 113
        d, exclude=(), ident=0,
105 114
        with_enumeration=False, recursive_enumeration=False):

Also available in: Unified diff