diff --git a/cinderclient/shell.py b/cinderclient/shell.py index 184b53a86..7e0a688d5 100644 --- a/cinderclient/shell.py +++ b/cinderclient/shell.py @@ -576,6 +576,12 @@ class OpenStackCinderShell(object): do_help, args) self.parser = subcommand_parser + 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 0 + if options.help or not argv: subcommand_parser.print_help() return 0 diff --git a/cinderclient/tests/unit/test_shell.py b/cinderclient/tests/unit/test_shell.py index 67440a99a..6156f36e5 100644 --- a/cinderclient/tests/unit/test_shell.py +++ b/cinderclient/tests/unit/test_shell.py @@ -16,6 +16,7 @@ import re import sys import unittest +import ddt import fixtures import keystoneauth1.exceptions as ks_exc from keystoneauth1.exceptions import DiscoveryFailure @@ -36,6 +37,7 @@ from cinderclient.tests.unit.fixture_data import keystone_client from cinderclient.tests.unit import utils +@ddt.ddt class ShellTest(utils.TestCase): FAKE_ENV = { @@ -132,6 +134,15 @@ class ShellTest(utils.TestCase): self.assertThat(help_text, matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE)) + @ddt.data('backup-create --help', '--help backup-create') + def test_dash_dash_help_on_subcommand(self, cmd): + required = ['.*?^Creates a volume backup.'] + help_text = self.shell(cmd) + + for r in required: + self.assertThat(help_text, + matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE)) + def register_keystone_auth_fixture(self, mocker, url): mocker.register_uri('GET', url, text=keystone_client.keystone_request_callback)