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
This commit is contained in:
Vadim Hmyrov
2016-10-06 17:27:33 +03:00
parent 6cbba52979
commit b0641b1d99
4 changed files with 44 additions and 3 deletions

View File

@@ -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)

View File

@@ -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()

View File

@@ -207,7 +207,7 @@ def do_node_list(cc, args):
'-d', '--driver',
metavar='<driver>',
required=True,
help='Driver used to control the node [REQUIRED].')
help='Driver used to control the node.')
@cliutils.arg(
'-i', '--driver-info',
metavar='<key=value>',

View File

@@ -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