summaryrefslogtreecommitdiff
path: root/qpid/tools/src
diff options
context:
space:
mode:
authorNuno Santos <nsantos@apache.org>2010-05-24 23:19:11 +0000
committerNuno Santos <nsantos@apache.org>2010-05-24 23:19:11 +0000
commitea8f03207a561361c7bf398c9a747b56eeedee28 (patch)
tree6edc28bf64067939158b2a42f294c1a9a64543d2 /qpid/tools/src
parentaa1ddcebf5a63c4908b08035b223b1ec1fa54037 (diff)
downloadqpid-python-ea8f03207a561361c7bf398c9a747b56eeedee28.tar.gz
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
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@947858 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/tools/src')
-rwxr-xr-xqpid/tools/src/py/qpid-cluster21
-rwxr-xr-xqpid/tools/src/py/qpid-config20
-rwxr-xr-xqpid/tools/src/py/qpid-route19
-rwxr-xr-xqpid/tools/src/py/qpid-stat20
-rwxr-xr-xqpid/tools/src/py/qpid-tool4
5 files changed, 62 insertions, 22 deletions
diff --git a/qpid/tools/src/py/qpid-cluster b/qpid/tools/src/py/qpid-cluster
index 7e608e4f2b..e02cca7a88 100755
--- a/qpid/tools/src/py/qpid-cluster
+++ b/qpid/tools/src/py/qpid-cluster
@@ -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:
diff --git a/qpid/tools/src/py/qpid-config b/qpid/tools/src/py/qpid-config
index f086ab9ac2..140628f737 100755
--- a/qpid/tools/src/py/qpid-config
+++ b/qpid/tools/src/py/qpid-config
@@ -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":
diff --git a/qpid/tools/src/py/qpid-route b/qpid/tools/src/py/qpid-route
index 156ab696f1..64a22c0614 100755
--- a/qpid/tools/src/py/qpid-route
+++ b/qpid/tools/src/py/qpid-route
@@ -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:
diff --git a/qpid/tools/src/py/qpid-stat b/qpid/tools/src/py/qpid-stat
index fd284359b3..ed4a6082c7 100755
--- a/qpid/tools/src/py/qpid-stat
+++ b/qpid/tools/src/py/qpid-stat
@@ -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:
diff --git a/qpid/tools/src/py/qpid-tool b/qpid/tools/src/py/qpid-tool
index c74595a359..e5affec74d 100755
--- a/qpid/tools/src/py/qpid-tool
+++ b/qpid/tools/src/py/qpid-tool
@@ -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()