From 2a39fcaf8cf6d20c2cfac46ddba661ddc9699f39 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Wed, 6 Jul 2016 14:24:30 +0200 Subject: [refactor] beautify cli output --- src/leap/bitmask/cli/bitmask_cli.py | 48 +++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 15 deletions(-) (limited to 'src/leap/bitmask/cli/bitmask_cli.py') diff --git a/src/leap/bitmask/cli/bitmask_cli.py b/src/leap/bitmask/cli/bitmask_cli.py index 76b27c94..0aafeb78 100755 --- a/src/leap/bitmask/cli/bitmask_cli.py +++ b/src/leap/bitmask/cli/bitmask_cli.py @@ -18,6 +18,7 @@ """ Bitmask Command Line interface: zmq client. """ +import json import sys from colorama import Fore @@ -31,30 +32,30 @@ from leap.bitmask.cli.user import User class BitmaskCLI(Command): - usage = '''bitmask_cli [] + usage = '''bitmaskctl [] Controls the Bitmask application. SERVICE COMMANDS: - user Handles Bitmask accounts - mail Bitmask Encrypted Mail - eip Encrypted Internet Proxy - keys Bitmask Keymanager + user Handles Bitmask accounts + mail Bitmask Encrypted Mail + eip Encrypted Internet Proxy + keys Bitmask Keymanager GENERAL COMMANDS: - version prints version number and exit - launch launch the Bitmask backend daemon - shutdown shutdown Bitmask backend daemon - status displays general status about the running Bitmask services - stats show some debug info about bitmask-core - help show this help message + version prints version number and exit + launch launch the Bitmask backend daemon + shutdown shutdown Bitmask backend daemon + status displays general status about the running Bitmask services + stats show some debug info about bitmask-core + help show this help message ''' - epilog = ("Use 'bitmask_cli help' to learn more " + epilog = ("Use 'bitmaskctl help' to learn more " "about each command.") - commands = ['shutdown', 'status', 'stats'] + commands = ['shutdown', 'stats'] def user(self, raw_args): user = User() @@ -82,9 +83,26 @@ GENERAL COMMANDS: return defer.succeed(None) def version(self, raw_args): - print Fore.GREEN + 'bitmask_cli: 0.0.1' + Fore.RESET + print(Fore.GREEN + 'bitmask_cli: ' + Fore.RESET + '0.0.1') self.data = ['version'] - return self._send() + return self._send(printer=self._print_version) + + def _print_version(self, version): + corever = version['version_core'] + print(Fore.GREEN + 'bitmask_core: ' + Fore.RESET + corever) + + def status(self, raw_args): + self.data = ['status'] + return self._send(printer=self._print_status) + + def _print_status(self, status): + statusdict = json.loads(status) + for key, value in statusdict.items(): + color = Fore.GREEN + if value == 'stopped': + color = Fore.RED + print(key.ljust(10) + ': ' + color + + value + Fore.RESET) def execute(): -- cgit v1.2.3