You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ns...@apache.org on 2010/05/25 01:19:12 UTC

svn commit: r947858 - in /qpid/trunk/qpid/tools/src/py: qpid-cluster qpid-config qpid-route qpid-stat qpid-tool

Author: nsantos
Date: Mon May 24 23:19:11 2010
New Revision: 947858

URL: http://svn.apache.org/viewvc?rev=947858&view=rev
Log:
Make behavior of command line tools consistent, regarding -h and --help options, as well as giving an appropriate error message for any invalid options passed on the command line

Modified:
    qpid/trunk/qpid/tools/src/py/qpid-cluster
    qpid/trunk/qpid/tools/src/py/qpid-config
    qpid/trunk/qpid/tools/src/py/qpid-route
    qpid/trunk/qpid/tools/src/py/qpid-stat
    qpid/trunk/qpid/tools/src/py/qpid-tool

Modified: qpid/trunk/qpid/tools/src/py/qpid-cluster
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/py/qpid-cluster?rev=947858&r1=947857&r2=947858&view=diff
==============================================================================
--- qpid/trunk/qpid/tools/src/py/qpid-cluster (original)
+++ qpid/trunk/qpid/tools/src/py/qpid-cluster Mon May 24 23:19:11 2010
@@ -38,12 +38,15 @@ class Config:
         self._showConn = False
         self._delConn = None
 
-def usage ():
+def usage (short=False):
     print "Usage:  qpid-cluster [OPTIONS] [broker-addr]"
     print
     print "             broker-addr is in the form:   [username/password@] hostname | ip-address [:<port>]"
     print "             ex:  localhost, 10.1.1.7:10000, broker-host:10000, guest/guest@localhost"
     print
+    if short:
+        return
+
     print "Options:"
     print "          --timeout seconds (10)  Maximum time to wait for broker connection"
     print "          -C [--all-connections]  View client connections to all cluster members"
@@ -244,11 +247,14 @@ def main(argv=None):
     try:
         config = Config()
         try:
-            longOpts = ("stop=", "all-stop", "force", "connections=", "all-connections" "del-connection=", "numeric", "timeout=")
-            (optlist, encArgs) = getopt.gnu_getopt(argv[1:], "s:kfCc:d:n", longOpts)
-        except:
-            usage()
-            return 1
+            longOpts = ("help", "stop=", "all-stop", "force", "connections=", "all-connections" "del-connection=", "numeric", "timeout=")
+            (optlist, encArgs) = getopt.gnu_getopt(argv[1:], "hs:kfCc:d:n", longOpts)
+        except Exception, e:
+            usage (short=True)
+            # make output match optparse-based tools' output, for consistent scripting
+            msg = str(e).replace('option', 'no such option:').replace('not recognized', '')
+            print "qpid-config: error:", msg
+            sys.exit (1)    
 
         try:
             encoding = locale.getpreferredencoding()
@@ -258,6 +264,9 @@ def main(argv=None):
 
         count = 0
         for opt in optlist:
+            if opt[0] == "-h" or opt[0] == "--help":
+                usage()
+                sys.exit(1)
             if opt[0] == "--timeout":
                 config._connTimeout = int(opt[1])
                 if config._connTimeout == 0:

Modified: qpid/trunk/qpid/tools/src/py/qpid-config
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/py/qpid-config?rev=947858&r1=947857&r2=947858&view=diff
==============================================================================
--- qpid/trunk/qpid/tools/src/py/qpid-config (original)
+++ qpid/trunk/qpid/tools/src/py/qpid-config Mon May 24 23:19:11 2010
@@ -57,7 +57,7 @@ MSG_SEQUENCE = "qpid.msg_sequence"
 IVE = "qpid.ive"
 QUEUE_EVENT_GENERATION = "qpid.queue_event_generation"
 
-def Usage ():
+def Usage (short=False):
     print "Usage:  qpid-config [OPTIONS]"
     print "        qpid-config [OPTIONS] exchanges [filter-string]"
     print "        qpid-config [OPTIONS] queues    [filter-string]"
@@ -70,6 +70,9 @@ def Usage ():
     print "                  <for type header>  [all|any] k1=v1 [, k2=v2...]"
     print "        qpid-config [OPTIONS] unbind <exchange-name> <queue-name> [binding-key]"
     print
+    if short:
+        return
+
     print "Options:"
     print "    --timeout seconds (10)                    Maximum time to wait for broker connection"
     print "    -b [ --bindings ]                         Show bindings in queue or exchange list"
@@ -452,13 +455,17 @@ def YN (bool):
 ##
 
 try:
-    longOpts = ("durable", "cluster-durable", "bindings", "broker-addr=", "file-count=",
+    longOpts = ("help", "durable", "cluster-durable", "bindings", "broker-addr=", "file-count=",
                 "file-size=", "max-queue-size=", "max-queue-count=", "limit-policy=",
                 "order=", "sequence", "ive", "generate-queue-events=", "force", "force-if-not-empty",
                 "force_if_used", "alternate-exchange=", "passive", "timeout=", "file=")
-    (optlist, encArgs) = getopt.gnu_getopt (sys.argv[1:], "a:bf:", longOpts)
-except:
-    Usage ()
+    (optlist, encArgs) = getopt.gnu_getopt (sys.argv[1:], "ha:bf:", longOpts)
+except Exception, e:
+    Usage (short=True)
+    # make output match optparse-based tools' output, for consistent scripting
+    msg = str(e).replace('option', 'no such option:').replace('not recognized', '')
+    print "qpid-config: error:", msg
+    sys.exit (1)    
 
 try:
     encoding = locale.getpreferredencoding()
@@ -467,6 +474,9 @@ except:
     cargs = encArgs
 
 for opt in optlist:
+    if opt[0] == "-h" or opt[0] == "--help":
+        Usage()
+        sys.exit(1)
     if opt[0] == "-b" or opt[0] == "--bindings":
         _recursive = True
     if opt[0] == "-a" or opt[0] == "--broker-addr":

Modified: qpid/trunk/qpid/tools/src/py/qpid-route
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/py/qpid-route?rev=947858&r1=947857&r2=947858&view=diff
==============================================================================
--- qpid/trunk/qpid/tools/src/py/qpid-route (original)
+++ qpid/trunk/qpid/tools/src/py/qpid-route Mon May 24 23:19:11 2010
@@ -26,7 +26,7 @@ import os
 import locale
 from qmf.console import Session, BrokerURL
 
-def Usage():
+def Usage(short=False):
     print "Usage:  qpid-route [OPTIONS] dynamic add <dest-broker> <src-broker> <exchange> [tag] [exclude-list]"
     print "        qpid-route [OPTIONS] dynamic del <dest-broker> <src-broker> <exchange>"
     print
@@ -42,6 +42,8 @@ def Usage():
     print "        qpid-route [OPTIONS] link del  <dest-broker> <src-broker>"
     print "        qpid-route [OPTIONS] link list [<dest-broker>]"
     print
+    if short:
+        return
     print "Options:"
     print "    --timeout seconds (10)   Maximum time to wait for broker connection"
     print "    -v [ --verbose ]         Verbose output"
@@ -406,10 +408,14 @@ def YN(val):
 ##
 
 try:
-    longOpts = ("verbose", "quiet", "durable", "del-empty-link", "src-local", "transport=", "ack=", "timeout=")
-    (optlist, encArgs) = getopt.gnu_getopt(sys.argv[1:], "vqdest:", longOpts)
-except:
-    Usage()
+    longOpts = ("help", "verbose", "quiet", "durable", "del-empty-link", "src-local", "transport=", "ack=", "timeout=")
+    (optlist, encArgs) = getopt.gnu_getopt(sys.argv[1:], "hvqdest:", longOpts)
+except Exception, e:
+    Usage(short=True)
+    # make output match optparse-based tools' output, for consistent scripting
+    msg = str(e).replace('option', 'no such option:').replace('not recognized', '')
+    print "qpid-config: error:", msg
+    sys.exit (1)    
 
 try:
     encoding = locale.getpreferredencoding()
@@ -418,6 +424,9 @@ except:
     cargs = encArgs
 
 for opt in optlist:
+    if opt[0] == "-h" or opt[0] == "--help":
+        Usage()
+        sys.exit(1)
     if opt[0] == "--timeout":
         _connTimeout = int(opt[1])
         if _connTimeout == 0:

Modified: qpid/trunk/qpid/tools/src/py/qpid-stat
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/py/qpid-stat?rev=947858&r1=947857&r2=947858&view=diff
==============================================================================
--- qpid/trunk/qpid/tools/src/py/qpid-stat (original)
+++ qpid/trunk/qpid/tools/src/py/qpid-stat Mon May 24 23:19:11 2010
@@ -35,12 +35,15 @@ _limit = 50
 _increasing = False
 _sortcol = None
 
-def Usage ():
+def Usage (short=False):
     print "Usage:  qpid-stat [OPTIONS] [broker-addr]"
     print
     print "             broker-addr is in the form:   [username/password@] hostname | ip-address [:<port>]"
     print "             ex:  localhost, 10.1.1.7:10000, broker-host:10000, guest/guest@localhost"
     print
+    if short:
+        return
+
     print "General Options:"
     print "    --timeout seconds (10)  Maximum time to wait for broker connection"
 #    print "     -n [--numeric]  Don't resolve names"
@@ -456,10 +459,14 @@ class BrokerManager(Console):
 ##
 
 try:
-    longOpts = ("top", "numeric", "sort-by=", "limit=", "increasing", "timeout=")
-    (optlist, encArgs) = getopt.gnu_getopt(sys.argv[1:], "bcequS:L:I", longOpts)
-except:
-    Usage()
+    longOpts = ("help", "top", "numeric", "sort-by=", "limit=", "increasing", "timeout=")
+    (optlist, encArgs) = getopt.gnu_getopt(sys.argv[1:], "hbcequS:L:I", longOpts)
+except Exception, e:
+    Usage(short=True)
+    # make output match optparse-based tools' output, for consistent scripting
+    msg = str(e).replace('option', 'no such option:').replace('not recognized', '')
+    print "qpid-config: error:", msg
+    sys.exit (1)    
 
 try:
     encoding = locale.getpreferredencoding()
@@ -468,6 +475,9 @@ except:
     cargs = encArgs
 
 for opt in optlist:
+    if opt[0] == "-h" or opt[0] == "--help":
+        Usage()
+        sys.exit(1)
     if opt[0] == "--timeout":
         _connTimeout = int(opt[1])
         if _connTimeout == 0:

Modified: qpid/trunk/qpid/tools/src/py/qpid-tool
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/py/qpid-tool?rev=947858&r1=947857&r2=947858&view=diff
==============================================================================
--- qpid/trunk/qpid/tools/src/py/qpid-tool (original)
+++ qpid/trunk/qpid/tools/src/py/qpid-tool Mon May 24 23:19:11 2010
@@ -597,7 +597,6 @@ class IdRegistry(object):
 def Usage():
   print "Usage:  qpid-tool [[<username>/<password>@]<target-host>[:<tcp-port>]]"
   print
-  sys.exit(1)
 
 #=========================================================
 # Main Program
@@ -612,6 +611,9 @@ if len(cargs) > 0:
 
 if _host[0] == '-':
   Usage()
+  if _host != '-h' and _host != "--help":
+    print "qpid-tool: error: no such option:", _host
+  sys.exit(1)
 
 disp = Display()
 



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org