[tor-commits] [ooni-probe/master] Handle the case where no command is specified.

art at torproject.org art at torproject.org
Tue Aug 19 08:00:15 UTC 2014


commit 2e4a26b3632b42a2b43ac3333820f6ec2612977e
Author: Arturo Filastò <art at fuffa.org>
Date:   Mon Aug 18 16:11:48 2014 +0200

    Handle the case where no command is specified.
---
 ooni/report/cli.py |   24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/ooni/report/cli.py b/ooni/report/cli.py
index 6f98574..2523c4f 100644
--- a/ooni/report/cli.py
+++ b/ooni/report/cli.py
@@ -27,6 +27,11 @@ class Options(usage.Options):
         sys.exit(0)
 
     def parseArgs(self, *args):
+        if len(args) == 0:
+            raise usage.UsageError(
+                "Must specify at least one command"
+            )
+            return
         self['command'] = args[0]
         if self['command'] not in ("upload", "status"):
             raise usage.UsageError(
@@ -39,15 +44,6 @@ class Options(usage.Options):
                 self['report_file'] = None
 
 
-def parse_options():
-    options = Options()
-    try:
-        options.parseOptions()
-    except Exception as exc:
-        print(exc)
-    return dict(options)
-
-
 def tor_check():
     if not config.tor.socks_port:
         print("Currently oonireport requires that you start Tor yourself "
@@ -57,7 +53,13 @@ def tor_check():
 
 def run():
     config.read_config_file()
-    options = parse_options()
+    options = Options()
+    try:
+        options.parseOptions()
+    except Exception as exc:
+        print("Error: %s" % exc)
+        print(options)
+        sys.exit(2)
     if options['command'] == "upload" and options['report_file']:
         tor_check()
         return tool.upload(options['report_file'],
@@ -69,3 +71,5 @@ def run():
                                options['bouncer'])
     elif options['command'] == "status":
         return tool.status()
+    else:
+        print(options)





More information about the tor-commits mailing list