Skip to content
Snippets Groups Projects
Commit ec5cc9ba authored by Jameson Rollins's avatar Jameson Rollins
Browse files

cli: better arg parsing error handling

parent cb2cefe5
No related branches found
No related tags found
No related merge requests found
...@@ -141,8 +141,11 @@ def main(): ...@@ -141,8 +141,11 @@ def main():
if args.ifo: if args.ifo:
for paramval in args.ifo: for paramval in args.ifo:
param, val = paramval.split('=', 1) try:
ifo[param] = float(val) param, val = paramval.split('=', 1)
ifo[param] = float(val)
except ValueError:
parser.error("Improper IFO parameter specification.")
if args.yaml: if args.yaml:
if not ifo: if not ifo:
...@@ -178,6 +181,8 @@ def main(): ...@@ -178,6 +181,8 @@ def main():
for path in args.save: for path in args.save:
if os.path.splitext(path)[1] in io.DATA_SAVE_FORMATS: if os.path.splitext(path)[1] in io.DATA_SAVE_FORMATS:
out_data_files.add(path) out_data_files.add(path)
else:
parser.exit(2, "Save file extension not specified.\n")
out_plot_files = set(args.save) - out_data_files out_plot_files = set(args.save) - out_data_files
if args.plot or out_plot_files: if args.plot or out_plot_files:
...@@ -215,9 +220,12 @@ def main(): ...@@ -215,9 +220,12 @@ def main():
for param in args.range.split(','): for param in args.range.split(','):
if not param: if not param:
continue continue
p, v = param.split('=') try:
if not v: p, v = param.split('=')
raise ValueError('missing parameter value "{}"'.format(p)) if not v:
raise ValueError
except ValueError:
parser.error("Improper range parameter specification.")
try: try:
v = float(v) v = float(v)
except ValueError: except ValueError:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment