[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [arm/master] Balk if there's unrecognized arguments



commit cc342a8accfebd44dc6256ab29946744fe9b2cd7
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sat Feb 21 18:33:00 2015 -0800

    Balk if there's unrecognized arguments
    
    Similar to a fix for stem: https://gitweb.torproject.org/stem.git/commit/?id=7753976dc7477a86fa8bc923292af3a09da7d660
---
 arm/arguments.py |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/arm/arguments.py b/arm/arguments.py
index d7820dd..b404486 100644
--- a/arm/arguments.py
+++ b/arm/arguments.py
@@ -78,11 +78,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 getopt.GetoptError("'%s' %s" % ("', '".join(unrecognized_args), error_msg))
   except getopt.GetoptError as exc:
     raise ValueError(msg('usage.invalid_arguments', error = 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)

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits