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:
@@ -58,8 +58,13 @@ def define_command(subparsers, command, callback, cmd_mapper):
|
|||||||
subparser.add_argument('-h', '--help', action='help',
|
subparser.add_argument('-h', '--help', action='help',
|
||||||
help=argparse.SUPPRESS)
|
help=argparse.SUPPRESS)
|
||||||
cmd_mapper[command] = subparser
|
cmd_mapper[command] = subparser
|
||||||
|
required_args = subparser.add_argument_group(_("Required arguments"))
|
||||||
|
|
||||||
for (args, kwargs) in 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)
|
subparser.set_defaults(func=callback)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -106,7 +106,7 @@ class ShellTest(utils.BaseTestCase):
|
|||||||
|
|
||||||
def test_help_on_subcommand(self):
|
def test_help_on_subcommand(self):
|
||||||
required = [
|
required = [
|
||||||
'.*?^usage: ironic chassis-show',
|
".*?^usage: ironic chassis-show",
|
||||||
".*?^Show detailed information about a chassis",
|
".*?^Show detailed information about a chassis",
|
||||||
]
|
]
|
||||||
argstrings = [
|
argstrings = [
|
||||||
@@ -118,6 +118,36 @@ class ShellTest(utils.BaseTestCase):
|
|||||||
self.assertThat(help_text,
|
self.assertThat(help_text,
|
||||||
matchers.MatchesRegex(r, self.re_options))
|
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):
|
def test_auth_param(self):
|
||||||
self.make_env(exclude='OS_USERNAME')
|
self.make_env(exclude='OS_USERNAME')
|
||||||
self.test_help()
|
self.test_help()
|
||||||
|
@@ -207,7 +207,7 @@ def do_node_list(cc, args):
|
|||||||
'-d', '--driver',
|
'-d', '--driver',
|
||||||
metavar='<driver>',
|
metavar='<driver>',
|
||||||
required=True,
|
required=True,
|
||||||
help='Driver used to control the node [REQUIRED].')
|
help='Driver used to control the node.')
|
||||||
@cliutils.arg(
|
@cliutils.arg(
|
||||||
'-i', '--driver-info',
|
'-i', '--driver-info',
|
||||||
metavar='<key=value>',
|
metavar='<key=value>',
|
||||||
|
@@ -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
|
Reference in New Issue
Block a user