summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/cli/command.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/leap/bitmask/cli/command.py')
-rw-r--r--src/leap/bitmask/cli/command.py23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/leap/bitmask/cli/command.py b/src/leap/bitmask/cli/command.py
index ac427c76..36552c03 100644
--- a/src/leap/bitmask/cli/command.py
+++ b/src/leap/bitmask/cli/command.py
@@ -31,15 +31,28 @@ from txzmq import ZmqRequestTimeoutError
from leap.bitmask.core import ENDPOINT
+appname = 'bitmaskctl'
+
+
def _print_result(result):
print Fore.GREEN + '%s' % result + Fore.RESET
+def default_dict_printer(result):
+ for key, value in result.items():
+ if value is None:
+ value = str(value)
+ print(Fore.RESET + key.ljust(10) + Fore.GREEN + value + Fore.RESET)
+
+
class Command(object):
+ """A generic command dispatcher.
+ Any command in the class attribute `commands` will be dispached and
+ represented with a generic printer."""
service = ''
- usage = '''%s %s <subcommand>''' % tuple(sys.argv[:2])
- epilog = ("Use '%s %s <subcommand> --help' to learn more "
- "about each command." % tuple(sys.argv[:2]))
+ usage = '''{name} <subcommand>'''.format(name=appname)
+ epilog = ("Use bitmaskctl <subcommand> --help' to learn more "
+ "about each command.")
commands = []
def __init__(self):
@@ -61,9 +74,11 @@ class Command(object):
except SystemExit:
return defer.succeed(None)
+ # if command is in the default list, send the bare command
+ # and use the default printer
if args.command in self.commands:
self.data += [args.command]
- return self._send()
+ return self._send(printer=default_dict_printer)
elif (args.command == 'execute' or
args.command.startswith('_') or