From 6427f39fe08a14e30525b060d606c59d257af94a Mon Sep 17 00:00:00 2001 From: Kyle Blatter Date: Thu, 4 Dec 2014 11:31:54 -0800 Subject: [PATCH] Add a help option with usage information Add a basic help option and usage description which is consistent with arcstat.py and dbufstat.py. This also adds support for long opts. Signed-off-by: Brian Behlendorf Signed-off-by: Kyle Blatter Signed-off-by: Ned Bass --- cmd/arc_summary/arc_summary.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/cmd/arc_summary/arc_summary.py b/cmd/arc_summary/arc_summary.py index 1456e58f37..2d76df82db 100755 --- a/cmd/arc_summary/arc_summary.py +++ b/cmd/arc_summary/arc_summary.py @@ -1064,22 +1064,43 @@ def zfs_header(): div2() +def usage(): + sys.stdout.write("Usage: arc_summary.py [-h] [-a] [-d] [-p PAGE]\n\n") + sys.stdout.write("\t -h, --help : " + "Print this help message and exit\n") + sys.stdout.write("\t -a, --alternate : " + "Show an alternate sysctl layout\n") + sys.stdout.write("\t -d, --description : " + "Show the sysctl descriptions\n") + sys.stdout.write("\t -p PAGE, --page=PAGE : " + "Select a single output page to display,\n") + sys.stdout.write("\t " + "should be an integer between 1 and " + str(len(unSub)) + "\n\n") + sys.stdout.write("Examples:\n") + sys.stdout.write("\tarc_summary.py -a\n") + sys.stdout.write("\tarc_summary.py -p 4\n") + sys.stdout.write("\tarc_summary.py -ad\n") + sys.stdout.write("\tarc_summary.py --page=2\n") + def main(): global show_sysctl_descriptions global alternate_sysctl_layout opts, args = getopt.getopt( - sys.argv[1:], "adp:" + sys.argv[1:], "adp:h", ["alternate", "description", "page=", "help"] ) args = {} for opt, arg in opts: - if opt == '-a': + if opt in ('-a', '--alternate'): args['a'] = True - if opt == '-d': + if opt in ('-d', '--description'): args['d'] = True - if opt == '-p': + if opt in ('-p', '--page'): args['p'] = arg + if opt in ('-h', '--help'): + usage() + sys.exit() Kstat = get_Kstat()