Skip to content

Commit 73a1d37

Browse files
author
Gabriel Monroy
committed
move parse_args() out of main, other flake8 fixes #16
1 parent 48fc8d1 commit 73a1d37

1 file changed

Lines changed: 23 additions & 9 deletions

File tree

client/deis.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,13 @@ def auth_register(self, args):
250250
"""
251251
Register a new user with a Deis controller
252252
253-
Usage: deis auth:register <controller> [--username=<username> --password=<password> --email=<email>]
253+
Usage: deis auth:register <controller> [options]
254+
255+
Options:
256+
257+
--username=USERNAME provide a username for the new account
258+
--password=PASSWORD provide a password for the new account
259+
--email=EMAIL provide an email address
254260
"""
255261
controller = args['<controller>']
256262
username = args.get('--username')
@@ -1156,15 +1162,10 @@ def releases_list(self, args):
11561162
print('Error!', response.text)
11571163

11581164

1159-
def main():
1165+
def parse_args(cmd):
11601166
"""
1161-
Create a client, parse the arguments received on the command line, and
1162-
call the appropriate method on the client.
1167+
Parse command-line args applying shortcuts and looking for help flags
11631168
"""
1164-
cli = DeisClient()
1165-
args = docopt(__doc__, version='Deis CLI {}'.format(__version__),
1166-
options_first=True)
1167-
cmd = args['<command>']
11681169
shortcuts = {
11691170
'register': 'auth:register',
11701171
'login': 'auth:login',
@@ -1178,7 +1179,7 @@ def main():
11781179
'scale': 'containers:scale',
11791180
'ps': 'containers:list',
11801181
}
1181-
if sys.argv[1] == 'help':
1182+
if cmd == 'help':
11821183
cmd = sys.argv[-1]
11831184
help_flag = True
11841185
else:
@@ -1195,6 +1196,19 @@ def main():
11951196
# convert : to _ for matching method names and docstrings
11961197
if ':' in cmd:
11971198
cmd = '_'.join(cmd.split(':'))
1199+
return cmd, help_flag
1200+
1201+
1202+
def main():
1203+
"""
1204+
Create a client, parse the arguments received on the command line, and
1205+
call the appropriate method on the client.
1206+
"""
1207+
cli = DeisClient()
1208+
args = docopt(__doc__, version='Deis CLI {}'.format(__version__),
1209+
options_first=True)
1210+
cmd = args['<command>']
1211+
cmd, help_flag = parse_args(cmd)
11981212
# print help if it was asked for
11991213
if help_flag:
12001214
if cmd != 'help':

0 commit comments

Comments
 (0)