From ff5ec25029db7669163854886be254fccde90e80 Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Thu, 16 Feb 2017 13:44:14 +0100 Subject: [feat] add json print to cli To improve scriptability we add '--json' param to the cli. - Resolves: #8771 --- src/leap/bitmask/cli/command.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/leap/bitmask/cli/command.py') diff --git a/src/leap/bitmask/cli/command.py b/src/leap/bitmask/cli/command.py index 95b0fe8d..15b864ff 100644 --- a/src/leap/bitmask/cli/command.py +++ b/src/leap/bitmask/cli/command.py @@ -57,7 +57,7 @@ class Command(object): "about each command.") commands = [] - def __init__(self, cfg): + def __init__(self, cfg, print_json=False): self.cfg = cfg color_init() @@ -68,6 +68,7 @@ class Command(object): self.data = [] if self.service: self.data = [self.service] + self.print_json = print_json def execute(self, raw_args): self.parser = argparse.ArgumentParser(usage=self.usage, @@ -112,7 +113,9 @@ class Command(object): def _check_err(self, stuff, printer): obj = json.loads(stuff[0]) - if not obj['error']: + if self.print_json: + print(json.dumps(obj, indent=2)) + elif not obj['error']: return printer(obj['result']) else: print Fore.RED + 'ERROR:' + '%s' % obj['error'] + Fore.RESET -- cgit v1.2.3