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:
@@ -465,6 +465,12 @@ class OpenStackManilaShell(object):
|
|||||||
self.parser = self.get_subcommand_parser(
|
self.parser = self.get_subcommand_parser(
|
||||||
os_api_version.get_major_version())
|
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:
|
if options.help or not argv:
|
||||||
self.parser.print_help()
|
self.parser.print_help()
|
||||||
return False
|
return False
|
||||||
|
@@ -290,12 +290,13 @@ class OpenstackManilaShellTest(utils.TestCase):
|
|||||||
def test_help_unknown_command(self):
|
def test_help_unknown_command(self):
|
||||||
self.assertRaises(exceptions.CommandError, self.shell, 'help foofoo')
|
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 = [
|
required = [
|
||||||
'.*?^usage: manila list',
|
'.*?^usage: manila list',
|
||||||
'.*?(?m)^List NAS shares with filters.',
|
'.*?(?m)^List NAS shares with filters.',
|
||||||
]
|
]
|
||||||
help_text = self.shell('help list')
|
help_text = self.shell(cmd)
|
||||||
for r in required:
|
for r in required:
|
||||||
self.assertThat(help_text,
|
self.assertThat(help_text,
|
||||||
matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE))
|
matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE))
|
||||||
|
@@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
fixes:
|
||||||
|
- Allow --help to print subcomands info. e.g.
|
||||||
|
``$ manila create --help``
|
Reference in New Issue
Block a user