Skip to content
This repository was archived by the owner on Aug 11, 2020. It is now read-only.

Commit 05ddd8b

Browse files
committed
add -c option, - option, allow arbitrary args by terminating option processing after -m, -c, -; update run usage string
1 parent 8b5e15f commit 05ddd8b

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

paperspace/main.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,12 @@ def main():
6666
print('run usage: %s' % run_usage(prog))
6767
sys.exit(not args)
6868
params = {}
69+
skip_arg_processing = False
6970
while args:
7071
opt = args.pop(0)
71-
if opt.startswith('--'):
72+
if opt == '-':
73+
skip_arg_processing = True
74+
elif opt.startswith('--') and not skip_arg_processing:
7275
param = opt[2:]
7376
if param in ['script', 'python', 'conda', 'ignoreFiles', 'apiKey', 'container', 'machineType', 'name',
7477
'project', 'projectId', 'command', 'workspace', 'dataset', 'registryUsername', 'registryPassword',
@@ -91,18 +94,19 @@ def main():
9194
print('error: invalid option: %s' % opt)
9295
print('usage: %s' % run_usage(prog))
9396
sys.exit(1)
94-
elif opt == '-m':
95-
params['module'] = True
97+
elif opt == '-m' and not skip_arg_processing:
98+
params['run_module'] = True
99+
skip_arg_processing = True
100+
elif opt == '-c' and not skip_arg_processing:
101+
params['run_command'] = True
102+
skip_arg_processing = True
96103
elif 'script' not in params:
97104
params['script'] = opt
98105
else:
99106
if 'script_args' not in params:
100107
params['script_args'] = [opt]
101108
else:
102109
params['script_args'].append(opt)
103-
if 'script' not in params:
104-
print('usage: %s' % run_usage(prog))
105-
sys.exit(1)
106110
res = run(params)
107111
if 'error' in res:
108112
print_json_pretty(res)
@@ -127,16 +131,17 @@ def apikey_usage(prog):
127131

128132

129133
def run_usage(prog):
130-
return format('%s run [-m] <python_script.py>\n'
134+
return format('%s run [options] [[-m] <script> [args] | -c "python code" | --command "shell cmd"]\n'
135+
' options:\n'
131136
' [--python 2|3]\n'
132137
' [--init [<init.sh>]]\n'
133138
' [--pipenv]\n'
134139
' [--req [<requirements.txt>]]\n'
135140
' [--workspace .|<workspace_path>]\n'
136-
' [--ignoreFiles "<file-or-dir>,<file-or-dir>,..."]\n'
137-
' [other jobs create options...]\n'
141+
' [--ignoreFiles "<file-or-dir>,..."]\n'
142+
' [jobs create options]\n'
138143
' [--dryrun]\n'
139-
' [script args]' % prog)
144+
' [-]' % prog)
140145

141146

142147
def usage(prog):

0 commit comments

Comments
 (0)