summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/cli/command.py
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2017-02-16 13:44:14 +0100
committerRuben Pollan <meskio@sindominio.net>2017-02-23 00:27:09 +0100
commitff5ec25029db7669163854886be254fccde90e80 (patch)
treecd0098ed9c4d3c840c053f9c794b687fcd3243d5 /src/leap/bitmask/cli/command.py
parent59cd23bd3e23bf2b439ad26271733a1b5c8edf68 (diff)
[feat] add json print to cli
To improve scriptability we add '--json' param to the cli. - Resolves: #8771
Diffstat (limited to 'src/leap/bitmask/cli/command.py')
-rw-r--r--src/leap/bitmask/cli/command.py7
1 files changed, 5 insertions, 2 deletions
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