Skip to content
Snippets Groups Projects
Commit 7753976d authored by Damian Johnson's avatar Damian Johnson
Browse files

Balk if an unrecognized argument is provided

Interesting, thought getopt did this. For both run_tests.py and the tor-prompt
providing an error when unrecognized arguments are provided. Caught by
Sebastian on...

  https://trac.torproject.org/projects/tor/ticket/14804
parent 34a900b5
No related branches found
No related tags found
No related merge requests found
......@@ -343,7 +343,16 @@ def _get_args(argv):
args = dict(ARGS)
for opt, arg in getopt.getopt(argv, OPT, OPT_EXPANDED)[0]:
try:
recognized_args, unrecognized_args = getopt.getopt(argv, OPT, OPT_EXPANDED)
if unrecognized_args:
error_msg = "aren't recognized arguments" if len(unrecognized_args) > 1 else "isn't a recognized argument"
raise ValueError("'%s' %s" % ("', '".join(unrecognized_args), error_msg))
except getopt.GetoptError as exc:
raise ValueError('%s (for usage provide --help)' % exc)
for opt, arg in recognized_args:
if opt in ('-a', '--all'):
args['run_unit'] = True
args['run_integ'] = True
......
......@@ -45,11 +45,15 @@ def parse(argv):
args = dict(DEFAULT_ARGS)
try:
getopt_results = getopt.getopt(argv, OPT, OPT_EXPANDED)[0]
recognized_args, unrecognized_args = getopt.getopt(argv, OPT, OPT_EXPANDED)
if unrecognized_args:
error_msg = "aren't recognized arguments" if len(unrecognized_args) > 1 else "isn't a recognized argument"
raise ValueError("'%s' %s" % ("', '".join(unrecognized_args), error_msg))
except getopt.GetoptError as exc:
raise ValueError('%s (for usage provide --help)' % exc)
for opt, arg in getopt_results:
for opt, arg in recognized_args:
if opt in ('-i', '--interface'):
if ':' in arg:
address, port = arg.split(':', 1)
......
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