From f19bfeb73fc19747bd02cbbd5c024de4dc86b5a8 Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Mon, 28 Aug 2017 17:04:14 +0200 Subject: [refactor] make the VPN location formating in the cli --- src/leap/bitmask/cli/vpn.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/leap/bitmask/cli') diff --git a/src/leap/bitmask/cli/vpn.py b/src/leap/bitmask/cli/vpn.py index 44556ac2..5a9cce9e 100644 --- a/src/leap/bitmask/cli/vpn.py +++ b/src/leap/bitmask/cli/vpn.py @@ -20,6 +20,8 @@ Bitmask Command Line interface: vpn module import argparse import sys +from colorama import Fore + from leap.bitmask.cli import command @@ -97,7 +99,7 @@ SUBCOMMANDS: def list(self, raw_args): self.data += ['list'] - return self._send(command.default_dict_printer) + return self._send(location_printer) def get_cert(self, raw_args): parser = argparse.ArgumentParser( @@ -115,3 +117,18 @@ SUBCOMMANDS: self.data += ['get_cert', uid] return self._send(command.default_dict_printer) + + +def location_printer(result): + def pprint(key, value): + print(Fore.RESET + key.ljust(20) + Fore.GREEN + + value + Fore.RESET) + + for provider, locations in result.items(): + for loc in locations.values(): + location_str = ("[%(country_code)s] %(name)s " + "(UTC%(timezone)s %(hemisphere)s)" % loc) + pprint(provider, location_str) + + if not locations.values(): + pprint(provider, "---") -- cgit v1.2.3