From 8c13e738c08f0b65feb6bd98c1c076f582140310 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 6 Jan 2017 13:28:28 -0500 Subject: [PATCH] Make usage/help more consistent across the commands Have every client command run argparse to get a chance at '-h'. When lacking arguments, always use print_help() to provide detail rather than usage. --- confluent_client/bin/nodeeventlog | 13 +++++++------ confluent_client/bin/nodefirmware | 11 ++++++----- confluent_client/bin/nodehealth | 9 ++++++--- confluent_client/bin/nodeidentify | 9 ++++++--- confluent_client/bin/nodeinventory | 9 +++++---- confluent_client/bin/nodelist | 4 ++-- confluent_client/bin/nodepower | 14 ++++++++------ confluent_client/bin/noderun | 2 +- confluent_client/bin/nodesensors | 6 +++--- confluent_client/bin/nodesetboot | 7 +++---- 10 files changed, 47 insertions(+), 37 deletions(-) diff --git a/confluent_client/bin/nodeeventlog b/confluent_client/bin/nodeeventlog index e95f31f1..fc7a68a1 100755 --- a/confluent_client/bin/nodeeventlog +++ b/confluent_client/bin/nodeeventlog @@ -1,7 +1,7 @@ #!/usr/bin/python # vim: tabstop=4 shiftwidth=4 softtabstop=4 -# Copyright 2015-2016 Lenovo +# Copyright 2015-2017 Lenovo # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ # limitations under the License. from datetime import datetime as dt +import optparse import os import sys @@ -26,13 +27,13 @@ if path.startswith('/opt'): import confluent.client as client - +argparser = optparse.OptionParser( + usage="Usage: %prog [options] noderange (clear)") +(options, args) = argparser.parse_args() try: - noderange = sys.argv[1] + noderange = args[0] except IndexError: - sys.stderr.write( - 'Usage: {0} [clear]\n'.format( - sys.argv[0])) + argparser.print_help() sys.exit(1) deletemode = False diff --git a/confluent_client/bin/nodefirmware b/confluent_client/bin/nodefirmware index 356d3363..1b51d6ec 100755 --- a/confluent_client/bin/nodefirmware +++ b/confluent_client/bin/nodefirmware @@ -1,7 +1,7 @@ #!/usr/bin/python # vim: tabstop=4 shiftwidth=4 softtabstop=4 -# Copyright 2016 Lenovo +# Copyright 2016-2017 Lenovo # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import optparse import os import sys path = os.path.dirname(os.path.realpath(__file__)) @@ -57,12 +58,12 @@ def printfirm(node, prefix, data): print('{0}: {1}: {2}'.format(node, prefix, version)) +argparser = optparse.OptionParser(usage="Usage: %prog ") +(options, args) = argparser.parse_args() try: - noderange = sys.argv[1] + noderange = args[0] except IndexError: - sys.stderr.write( - 'Usage: {0} \n'.format( - sys.argv[0])) + argparser.print_help() sys.exit(1) try: session = client.Command() diff --git a/confluent_client/bin/nodehealth b/confluent_client/bin/nodehealth index 75a7c6b0..294a73b4 100755 --- a/confluent_client/bin/nodehealth +++ b/confluent_client/bin/nodehealth @@ -1,7 +1,7 @@ #!/usr/bin/env python # vim: tabstop=4 shiftwidth=4 softtabstop=4 -# Copyright 2015 Lenovo +# Copyright 2015-2017 Lenovo # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ # limitations under the License. import codecs +import optparse import os import sys @@ -28,10 +29,12 @@ import confluent.client as client sys.stdout = codecs.getwriter('utf8')(sys.stdout) +argparser = optparse.OptionParser(usage="Usage: %prog ") +(options, args) = argparser.parse_args() try: - noderange = sys.argv[1] + noderange = args[0] except IndexError: - sys.stderr.write('Usage: {0} \n'.format(sys.argv[0])) + argparser.print_help() sys.exit(1) diff --git a/confluent_client/bin/nodeidentify b/confluent_client/bin/nodeidentify index 956827ce..17c397d9 100755 --- a/confluent_client/bin/nodeidentify +++ b/confluent_client/bin/nodeidentify @@ -1,7 +1,7 @@ #!/usr/bin/env python # vim: tabstop=4 shiftwidth=4 softtabstop=4 -# Copyright 2015 Lenovo +# Copyright 2015-2017 Lenovo # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import optparse import os import sys @@ -25,10 +26,12 @@ if path.startswith('/opt'): import confluent.client as client +argparser = optparse.OptionParser(usage="Usage: %prog [on|off]") +(options, args) = argparser.parse_args() try: - noderange = sys.argv[1] + noderange = args[0] except IndexError: - sys.stderr.write('Usage: {0} [on|off]\n'.format(sys.argv[0])) + argparser.print_help() sys.exit(1) identifystate = None diff --git a/confluent_client/bin/nodeinventory b/confluent_client/bin/nodeinventory index 8fc9caec..83a44bd7 100755 --- a/confluent_client/bin/nodeinventory +++ b/confluent_client/bin/nodeinventory @@ -1,7 +1,7 @@ #!/usr/bin/python # vim: tabstop=4 shiftwidth=4 softtabstop=4 -# Copyright 2016 Lenovo +# Copyright 2016-2017 Lenovo # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import optparse import os import sys path = os.path.dirname(os.path.realpath(__file__)) @@ -69,12 +70,12 @@ def printerror(res, node=None): exitcode = 1 +argparser = optparse.OptionParser(usage="Usage: %prog ") +(options, args) = argparser.parse_args() try: noderange = sys.argv[1] except IndexError: - sys.stderr.write( - 'Usage: {0} \n'.format( - sys.argv[0])) + argparser.print_help() sys.exit(1) try: session = client.Command() diff --git a/confluent_client/bin/nodelist b/confluent_client/bin/nodelist index 14b3fc87..50245628 100755 --- a/confluent_client/bin/nodelist +++ b/confluent_client/bin/nodelist @@ -1,7 +1,7 @@ #!/usr/bin/env python # vim: tabstop=4 shiftwidth=4 softtabstop=4 -# Copyright 2015 Lenovo +# Copyright 2015-2017 Lenovo # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -42,7 +42,7 @@ def attrrequested(attr, attrlist, seenattributes): return True return False argparser = optparse.OptionParser( - usage="Usage: %prog [options] noderange [list of attributes") + usage="Usage: %prog [options] noderange [list of attributes]") argparser.add_option('-b', '--blame', action='store_true', help='Show information about how attributes inherited') (options, args) = argparser.parse_args() diff --git a/confluent_client/bin/nodepower b/confluent_client/bin/nodepower index 7dbb8722..6711aea0 100755 --- a/confluent_client/bin/nodepower +++ b/confluent_client/bin/nodepower @@ -1,7 +1,7 @@ #!/usr/bin/env python # vim: tabstop=4 shiftwidth=4 softtabstop=4 -# Copyright 2015 Lenovo +# Copyright 2015-2017 Lenovo # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import optparse import os import sys @@ -25,13 +26,14 @@ if path.startswith('/opt'): import confluent.client as client - +argparser = optparse.OptionParser( + usage="Usage: %prog [options] noderange " + "([status|on|off|shutdown|boot|reset])") +(options, args) = argparser.parse_args() try: - noderange = sys.argv[1] + noderange = args[0] except IndexError: - sys.stderr.write( - 'Usage: {0} ([status|on|off|shutdown|boot|reset]\n'.format( - sys.argv[0])) + argparser.print_help() sys.exit(1) setstate = None diff --git a/confluent_client/bin/noderun b/confluent_client/bin/noderun index 4a614c12..dbebd4b2 100755 --- a/confluent_client/bin/noderun +++ b/confluent_client/bin/noderun @@ -1,7 +1,7 @@ #!/usr/bin/env python # vim: tabstop=4 shiftwidth=4 softtabstop=4 -# Copyright 2016 Lenovo +# Copyright 2016-2017 Lenovo # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/confluent_client/bin/nodesensors b/confluent_client/bin/nodesensors index a086f4d3..3c9827a3 100755 --- a/confluent_client/bin/nodesensors +++ b/confluent_client/bin/nodesensors @@ -1,7 +1,7 @@ #!/usr/bin/env python # vim: tabstop=4 shiftwidth=4 softtabstop=4 -# Copyright 2015 Lenovo +# Copyright 2015-2017 Lenovo # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -40,7 +40,7 @@ sensorcollections = { argparser = optparse.OptionParser( - usage="Usage: %prog [options] noderange [sensor(s)") + usage="Usage: %prog [options] noderange ([sensor(s)])") argparser.add_option('-i', '--interval', type='float', help='Interval to do repeated samples over') argparser.add_option('-n', '--numreadings', type='int', @@ -60,7 +60,7 @@ if options.numreadings: try: noderange = args[0] except IndexError: - argparser.print_usage() + argparser.print_help() sys.exit(1) sensors = [] for sensorgroup in args[1:]: diff --git a/confluent_client/bin/nodesetboot b/confluent_client/bin/nodesetboot index 9a26e1bf..bbe71d46 100755 --- a/confluent_client/bin/nodesetboot +++ b/confluent_client/bin/nodesetboot @@ -26,7 +26,8 @@ if path.startswith('/opt'): import confluent.client as client -argparser = optparse.OptionParser() +argparser = optparse.OptionParser( + usage='Usage: %prog [options] noderange [default|cd|network|setup|hd]') argparser.add_option('-b', '--bios', dest='biosmode', action='store_true', default=False, help='Request BIOS style boot (rather than UEFI)') @@ -40,9 +41,7 @@ argparser.add_option('-p', '--persist', dest='persist', action='store_true', try: noderange = args[0] except IndexError: - sys.stderr.write( - 'Usage: {0} [default|cd|network|setup|hd]\n'.format( - sys.argv[0])) + argparser.print_help() sys.exit(1) bootdev = None if len(sys.argv) > 2: