From b0641b1d996e78d6f771e3c635d684c27988bf37 Mon Sep 17 00:00:00 2001 From: Vadim Hmyrov Date: Thu, 6 Oct 2016 17:27:33 +0300 Subject: [PATCH] List required arguments in '--help' message in Ironic Client. The aim of this patch is to improve commands 'ironic help node-create' and 'ironic help port-create' so that the required arguments are listed in a dedicated section, but not in section 'optional arguments'. Change-Id: I73e0179170b3bb446bd9b14b095eac8ce8b5924b Closes-Bug: #1518959 --- ironicclient/common/utils.py | 7 +++- ironicclient/tests/unit/test_shell.py | 32 ++++++++++++++++++- ironicclient/v1/node_shell.py | 2 +- ...e-create-port-create-b213bb28bcc94743.yaml | 6 ++++ 4 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/show-required-arguments-in-help-commands-of-node-create-port-create-b213bb28bcc94743.yaml diff --git a/ironicclient/common/utils.py b/ironicclient/common/utils.py index 70e77eecc..977464ed7 100644 --- a/ironicclient/common/utils.py +++ b/ironicclient/common/utils.py @@ -58,8 +58,13 @@ def define_command(subparsers, command, callback, cmd_mapper): subparser.add_argument('-h', '--help', action='help', help=argparse.SUPPRESS) cmd_mapper[command] = subparser + required_args = subparser.add_argument_group(_("Required arguments")) + for (args, kwargs) in arguments: - subparser.add_argument(*args, **kwargs) + if kwargs.get('required'): + required_args.add_argument(*args, **kwargs) + else: + subparser.add_argument(*args, **kwargs) subparser.set_defaults(func=callback) diff --git a/ironicclient/tests/unit/test_shell.py b/ironicclient/tests/unit/test_shell.py index fe1bc0f76..259b5b945 100644 --- a/ironicclient/tests/unit/test_shell.py +++ b/ironicclient/tests/unit/test_shell.py @@ -106,7 +106,7 @@ class ShellTest(utils.BaseTestCase): def test_help_on_subcommand(self): required = [ - '.*?^usage: ironic chassis-show', + ".*?^usage: ironic chassis-show", ".*?^Show detailed information about a chassis", ] argstrings = [ @@ -118,6 +118,36 @@ class ShellTest(utils.BaseTestCase): self.assertThat(help_text, matchers.MatchesRegex(r, self.re_options)) + def test_required_args_on_node_create_help(self): + required = [ + ".*?^usage: ironic node-create", + ".*?^Register a new node with the Ironic service", + ".*?^Required arguments:", + ] + argstrings = [ + 'help node-create', + ] + for argstr in argstrings: + help_text = self.shell(argstr) + for r in required: + self.assertThat(help_text, + matchers.MatchesRegex(r, self.re_options)) + + def test_required_args_on_port_create_help(self): + required = [ + ".*?^usage: ironic port-create", + ".*?^Create a new port", + ".*?^Required arguments:", + ] + argstrings = [ + 'help port-create', + ] + for argstr in argstrings: + help_text = self.shell(argstr) + for r in required: + self.assertThat(help_text, + matchers.MatchesRegex(r, self.re_options)) + def test_auth_param(self): self.make_env(exclude='OS_USERNAME') self.test_help() diff --git a/ironicclient/v1/node_shell.py b/ironicclient/v1/node_shell.py index a9df76b78..95a32cf6d 100644 --- a/ironicclient/v1/node_shell.py +++ b/ironicclient/v1/node_shell.py @@ -207,7 +207,7 @@ def do_node_list(cc, args): '-d', '--driver', metavar='', required=True, - help='Driver used to control the node [REQUIRED].') + help='Driver used to control the node.') @cliutils.arg( '-i', '--driver-info', metavar='', diff --git a/releasenotes/notes/show-required-arguments-in-help-commands-of-node-create-port-create-b213bb28bcc94743.yaml b/releasenotes/notes/show-required-arguments-in-help-commands-of-node-create-port-create-b213bb28bcc94743.yaml new file mode 100644 index 000000000..4d9e00b9a --- /dev/null +++ b/releasenotes/notes/show-required-arguments-in-help-commands-of-node-create-port-create-b213bb28bcc94743.yaml @@ -0,0 +1,6 @@ +fixes: + - | + Starting with this release the output of + commands ``ironic help node-create`` and + ``ironic help port-create`` will show which + arguments are required \ No newline at end of file