Merge "Fixes CLI client called without subcommands"
This commit is contained in:
@@ -717,7 +717,7 @@ class OpenStackImagesShell(object):
|
|||||||
help='Display help for <subcommand>.')
|
help='Display help for <subcommand>.')
|
||||||
def do_help(self, args, parser):
|
def do_help(self, args, parser):
|
||||||
"""Display help about this program or one of its subcommands."""
|
"""Display help about this program or one of its subcommands."""
|
||||||
command = getattr(args, 'command') or ''
|
command = getattr(args, 'command', '')
|
||||||
|
|
||||||
if command:
|
if command:
|
||||||
if args.command in self.subcommands:
|
if args.command in self.subcommands:
|
||||||
@@ -725,13 +725,14 @@ class OpenStackImagesShell(object):
|
|||||||
else:
|
else:
|
||||||
raise exc.CommandError("'%s' is not a valid subcommand" %
|
raise exc.CommandError("'%s' is not a valid subcommand" %
|
||||||
args.command)
|
args.command)
|
||||||
|
command = ' ' + command
|
||||||
else:
|
else:
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
|
|
||||||
if not args.os_image_api_version or args.os_image_api_version == '2':
|
if not args.os_image_api_version or args.os_image_api_version == '2':
|
||||||
print()
|
print()
|
||||||
print(("Run `glance --os-image-api-version 1 help%s` "
|
print(("Run `glance --os-image-api-version 1 help%s` "
|
||||||
"for v1 help") % (' ' + command))
|
"for v1 help") % command)
|
||||||
|
|
||||||
def do_bash_completion(self, _args):
|
def do_bash_completion(self, _args):
|
||||||
"""Prints arguments for bash_completion.
|
"""Prints arguments for bash_completion.
|
||||||
|
|||||||
@@ -158,6 +158,13 @@ class ShellTest(testutils.TestCase):
|
|||||||
self.assertEqual(0, actual)
|
self.assertEqual(0, actual)
|
||||||
self.assertFalse(et_mock.called)
|
self.assertFalse(et_mock.called)
|
||||||
|
|
||||||
|
def test_blank_call(self):
|
||||||
|
shell = openstack_shell.OpenStackImagesShell()
|
||||||
|
with mock.patch.object(shell, '_get_endpoint_and_token') as et_mock:
|
||||||
|
actual = shell.main('')
|
||||||
|
self.assertEqual(0, actual)
|
||||||
|
self.assertFalse(et_mock.called)
|
||||||
|
|
||||||
def test_help_on_subcommand_error(self):
|
def test_help_on_subcommand_error(self):
|
||||||
self.assertRaises(exc.CommandError, shell,
|
self.assertRaises(exc.CommandError, shell,
|
||||||
'--os-image-api-version 2 help bad')
|
'--os-image-api-version 2 help bad')
|
||||||
|
|||||||
Reference in New Issue
Block a user