allow '--help' to print subcomands info

Currently, we only allow $manila help subcomand to print
subcomands info, if we are using $manila subcomand --help,
it will print all the subcomands info, that is not what we
want, this change is to allow '--help' to print subcomands
info. finally we can see the following comands are equals:

$ manila --help list
$ manila list --help
$ manila help list

Change-Id: I926defd6c5d3b8d87b038e2c63db694b40a88359
Close-bug: #1771097
This commit is contained in:
junboli 2018-05-23 08:43:06 +08:00
parent a5b63f32a1
commit b0b08cc650
3 changed files with 13 additions and 2 deletions

View File

@ -465,6 +465,12 @@ class OpenStackManilaShell(object):
self.parser = self.get_subcommand_parser(
os_api_version.get_major_version())
if argv and len(argv) > 1 and '--help' in argv:
argv = [x for x in argv if x != '--help']
if argv[0] in self.subcommands:
self.subcommands[argv[0]].print_help()
return False
if options.help or not argv:
self.parser.print_help()
return False

View File

@ -290,12 +290,13 @@ class OpenstackManilaShellTest(utils.TestCase):
def test_help_unknown_command(self):
self.assertRaises(exceptions.CommandError, self.shell, 'help foofoo')
def test_help_on_subcommand(self):
@ddt.data('list --help', '--help list', 'help list')
def test_help_on_subcommand(self, cmd):
required = [
'.*?^usage: manila list',
'.*?(?m)^List NAS shares with filters.',
]
help_text = self.shell('help list')
help_text = self.shell(cmd)
for r in required:
self.assertThat(help_text,
matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE))

View File

@ -0,0 +1,4 @@
---
fixes:
- Allow --help to print subcomands info. e.g.
``$ manila create --help``