summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/cli/user.py
diff options
context:
space:
mode:
authorKali Kaneko (leap communications) <kali@leap.se>2016-10-03 17:40:09 -0400
committerKali Kaneko (leap communications) <kali@leap.se>2016-10-04 11:48:30 -0400
commitaf27100e35f30f91f3c8f3eb4b8fcef978d11eae (patch)
tree92e1bdb9ebdb8e00aa84dbfefbda1b75e6cb883c /src/leap/bitmask/cli/user.py
parentff3ed1e9418eab21fd42bb5ddd96a3851a25801c (diff)
[feature] handle invite codes
In the command line, --invitecode is a new optional parameter to the command "user create". bonafide service handles the invite codes. javascript library should be updated accordingly - Resolves: #7550
Diffstat (limited to 'src/leap/bitmask/cli/user.py')
-rw-r--r--src/leap/bitmask/cli/user.py39
1 files changed, 33 insertions, 6 deletions
diff --git a/src/leap/bitmask/cli/user.py b/src/leap/bitmask/cli/user.py
index 8d3484cc..d1014ee7 100644
--- a/src/leap/bitmask/cli/user.py
+++ b/src/leap/bitmask/cli/user.py
@@ -20,6 +20,7 @@ Bitmask Command Line interface: user
import argparse
import getpass
import sys
+from copy import copy
from colorama import Fore
@@ -50,9 +51,27 @@ SUBCOMMANDS:
self.data.append('user')
def create(self, raw_args):
- username = self.username(raw_args)
- passwd = self._getpass_twice()
- self.data += ['create', username, passwd, 'true']
+ args = tuple([command.appname] + sys.argv[1:4])
+ parser = argparse.ArgumentParser(
+ description='Bitmask user',
+ prog='%s %s %s %s' % args)
+ parser.add_argument('--invitecode', **_invitecode_kw)
+ parser.add_argument('username', **_username_kw)
+
+ subargs = parser.parse_args(raw_args)
+
+ # username parsing is factored out, but won't
+ # accept the optional parameters. so strip them.
+ args = copy(raw_args)
+ for (index, item) in enumerate(args):
+ if item.startswith('--'):
+ args.pop(index + 1)
+ args.pop(index)
+
+ username = self.username(args)
+ passwd = self.getpass_twice()
+ self.data += ['create', username, passwd,
+ subargs.invite, 'true']
return self._send(printer=command.default_dict_printer)
def auth(self, raw_args):
@@ -82,11 +101,10 @@ SUBCOMMANDS:
parser = argparse.ArgumentParser(
description='Bitmask user',
prog='%s %s %s' % args)
- parser.add_argument('username', nargs=1,
- help='username ID, in the form <user@example.org>')
+ parser.add_argument('username', **_username_kw)
subargs = parser.parse_args(raw_args)
- username = subargs.username[0]
+ username = subargs.username
if not username:
self._error("Missing username ID but needed for this command")
if '@' not in username:
@@ -110,3 +128,12 @@ SUBCOMMANDS:
if u['authenticated']:
color = Fore.GREEN
print(color + u['userid'] + Fore.RESET)
+
+_username_kw = {
+ 'nargs': '?',
+ 'help': 'username ID, in the form <user@example.org>'}
+
+_invitecode_kw = {
+ 'dest': 'invite',
+ 'default': 'none', 'action': 'store', 'nargs': '?', 'type': str,
+ 'help': 'invite code, if needed to register with this provider'}