Merge "Allow --help for specific commands"

This commit is contained in:
Zuul
2018-05-03 09:58:55 +00:00
committed by Gerrit Code Review
2 changed files with 17 additions and 0 deletions

View File

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

View File

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