Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MB-6663: add help option for cbclusterstats tool

Actually getting it for free.

Change-Id: I2e445d832cc0cb7866e102a559cb4cd0b7a5623a
Reviewed-on: http://review.couchbase.org/21329
Reviewed-by: Steve Yen <steve.yen@gmail.com>
Tested-by: Bin Cui <bin.cui@gmail.com>
  • Loading branch information...
commit 0bc659c78e1f2d822e658778f857c8dacc7a01e5 1 parent ea1b260
@bcui6611 bcui6611 authored Peter Wansch committed
Showing with 30 additions and 49 deletions.
  1. +30 −49 cbclusterstats
View
79 cbclusterstats
@@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-import getopt
+from optparse import OptionParser
import sys
import logging
@@ -12,58 +12,39 @@ log = logging.getLogger('cbclusterstats')
log.setLevel(logging.INFO)
log.addHandler(logging.StreamHandler())
-def parse_opt():
- (cluster, user, password, txtfile) = ('', '', '', 'clusterstats.txt')
-
- try:
- (opts, _args) = getopt.getopt(sys.argv[1:],
- 'c:dp:u:o:', [
- 'cluster=',
- 'debug',
- 'password=',
- 'user=',
- 'txt=',
- ])
- except getopt.GetoptError, err:
- usage(err)
-
- for (opt, arg) in opts:
- if opt in ('-c', '--cluster'):
- cluster = arg
- if opt in ('-u', '--user'):
- user = arg
- if opt in ('-p', '--password'):
- password = arg
- if opt in ('-d', '--debug'):
- log.setLevel(logging.DEBUG)
- if opt in ('-o', '--output'):
- txtfile = arg
-
- if not cluster or not user or not password:
- usage()
- return (cluster, user, password, txtfile, opts)
-def usage(error_msg=''):
- if error_msg:
- print "ERROR: %s" % error_msg
+def parse_opt():
+ usage = "usage: %prog CLUSTER USERNAME PASSWORD OPTIONS"
+
+ parser = OptionParser(usage)
+
+ parser.add_option('-c', '--cluster', dest='cluster', default='',
+ help='default port is 8091',
+ metavar='HOST[:PORT]')
+ parser.add_option('-u', '--user', dest='user', default='',
+ help='admin username of the cluster',
+ metavar='USERNAME')
+ parser.add_option('-p', '--password', dest='password', default='',
+ help='admin password of the cluster',
+ metavar='PASSWORD')
+ parser.add_option('-o', '--output', dest='txtfile', default='clusterstats.txt',
+ help='default output filename is "clusterstats.txt"',
+ metavar='FILENAME')
+ parser.add_option('-d', '--debug', dest='debug', default=False,
+ action="store_true")
+
+ options, args = parser.parse_args()
+
+ if options.debug:
+ log.setLevel(logging.DEBUG)
+
+ if not options.cluster or not options.user or not options.password:
+ parser.print_help()
sys.exit(2)
- print """cbclusterstats - cluster key performance indicator stats
-
-usage: cbclusterstats CLUSTER USERNAME PASSWORD OPTIONS
-
-CLUSTER:
- --cluster=HOST[:PORT] or -c HOST[:PORT] Default port is 8091
-USERNAME:
- -u USERNAME, --user=USERNAME admin username of the cluster
-PASSWORD:
- -p PASSWORD, --password=PASSWORD admin password of the cluster
-OPTIONS:
- -o FILENAME, --output=FILENAME Default output filename is 'clusterstats.txt'
- -d, --debug
+ return options.cluster, options.user, options.password, options.txtfile, \
+ args
-"""
- sys.exit(2)
def main():
(cluster, user, password, txtfile, opts) = parse_opt()
Please sign in to comment.
Something went wrong with that request. Please try again.