本文整理汇总了Python中cliff.commandmanager.CommandManager方法的典型用法代码示例。如果您正苦于以下问题:Python commandmanager.CommandManager方法的具体用法?Python commandmanager.CommandManager怎么用?Python commandmanager.CommandManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cliff.commandmanager
的用法示例。
在下文中一共展示了commandmanager.CommandManager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _load_commands
# 需要导入模块: from cliff import commandmanager [as 别名]
# 或者: from cliff.commandmanager import CommandManager [as 别名]
def _load_commands(self):
# TODO(sfinucan): We should probably add this wildcarding functionality
# to the CommandManager itself to allow things like "show me the
# commands like 'foo *'"
command_pattern = self.options.get('command')
manager = commandmanager.CommandManager(self.arguments[0])
if command_pattern:
commands = [x for x in manager.commands
if fnmatch.fnmatch(x, command_pattern)]
else:
commands = manager.commands.keys()
if not commands:
msg = 'No commands found in the "{}" namespace'
if command_pattern:
msg += ' using the "{}" command name/pattern'
msg += ('. Are you sure this is correct and the application being '
'documented is installed?')
raise self.warning(msg.format(self.arguments[0], command_pattern))
return dict((name, self._load_command(manager, name))
for name in commands)
示例2: test_conflicting_option_should_throw
# 需要导入模块: from cliff import commandmanager [as 别名]
# 或者: from cliff.commandmanager import CommandManager [as 别名]
def test_conflicting_option_should_throw(self):
class MyApp(application.App):
def __init__(self):
super(MyApp, self).__init__(
description='testing',
version='0.1',
command_manager=commandmanager.CommandManager('tests'),
)
def build_option_parser(self, description, version):
parser = super(MyApp, self).build_option_parser(description,
version)
parser.add_argument(
'-h', '--help',
default=self, # tricky
help="Show help message and exit.",
)
self.assertRaises(
argparse.ArgumentError,
MyApp,
)
示例3: test_conflicting_option_custom_arguments_should_not_throw
# 需要导入模块: from cliff import commandmanager [as 别名]
# 或者: from cliff.commandmanager import CommandManager [as 别名]
def test_conflicting_option_custom_arguments_should_not_throw(self):
class MyApp(application.App):
def __init__(self):
super(MyApp, self).__init__(
description='testing',
version='0.1',
command_manager=commandmanager.CommandManager('tests'),
)
def build_option_parser(self, description, version):
argparse_kwargs = {'conflict_handler': 'resolve'}
parser = super(MyApp, self).build_option_parser(
description,
version,
argparse_kwargs=argparse_kwargs)
parser.add_argument(
'-h', '--help',
default=self, # tricky
help="Show help message and exit.",
)
MyApp()
示例4: test_get_command_names
# 需要导入模块: from cliff import commandmanager [as 别名]
# 或者: from cliff.commandmanager import CommandManager [as 别名]
def test_get_command_names(self):
mock_cmd_one = mock.Mock()
mock_cmd_one.name = 'one'
mock_cmd_two = mock.Mock()
mock_cmd_two.name = 'cmd two'
mock_pkg_resources = mock.Mock(
return_value=[mock_cmd_one, mock_cmd_two],
)
with mock.patch(
'pkg_resources.iter_entry_points',
mock_pkg_resources,
) as iter_entry_points:
mgr = commandmanager.CommandManager('test')
iter_entry_points.assert_called_once_with('test')
cmds = mgr.get_command_names('test')
self.assertEqual(['one', 'cmd two'], cmds)
示例5: __init__
# 需要导入模块: from cliff import commandmanager [as 别名]
# 或者: from cliff.commandmanager import CommandManager [as 别名]
def __init__(self):
"""
Initialization function of the class. It creates instances
of the lightbulb CLI show and use functionalities.
"""
super(LightBulb, self).__init__(
description='LightBulb App',
version='0.1',
command_manager=CommandManager('cliff.lightbulb'),
deferred_help=False,
)
self.library = LibraryModules(self, self, None)
self.librarycat = LibraryCat(self, self, None)
self.startsaved = StartSaved(self, self, None)
self.use = Use(self, self, None)
self.back = Back(self, self, None)
self.define = Define(self, self, None)
示例6: __init__
# 需要导入模块: from cliff import commandmanager [as 别名]
# 或者: from cliff.commandmanager import CommandManager [as 别名]
def __init__(self, **kwargs):
self.client = None
# Patch command.Command to add a default auth_required = True
command.Command.auth_required = True
# Some commands do not need authentication
help.HelpCommand.auth_required = False
complete.CompleteCommand.auth_required = False
super(Barbican, self).__init__(
description=__doc__.strip(),
version=barbicanclient.__version__,
command_manager=commandmanager.CommandManager(
'openstack.key_manager.v1'),
deferred_help=True,
**kwargs
)
示例7: __init__
# 需要导入模块: from cliff import commandmanager [as 别名]
# 或者: from cliff.commandmanager import CommandManager [as 别名]
def __init__(self, apiversion):
super(TackerShell, self).__init__(
description=__doc__.strip(),
version=VERSION,
command_manager=commandmanager.CommandManager('tacker.cli'), )
self.commands = COMMANDS
for k, v in self.commands[apiversion].items():
self.command_manager.add_command(k, v)
self._register_extensions(VERSION)
# Pop the 'complete' to correct the outputs of 'tacker help'.
self.command_manager.commands.pop('complete')
# This is instantiated in initialize_app() only when using
# password flow auth
self.auth_client = None
self.api_version = apiversion
示例8: __init__
# 需要导入模块: from cliff import commandmanager [as 别名]
# 或者: from cliff.commandmanager import CommandManager [as 别名]
def __init__(self):
super(AraCli, self).__init__(
description='A CLI client to query ARA databases',
version=__version__,
command_manager=CommandManager('ara.cli'),
deferred_help=True)
示例9: __init__
# 需要导入模块: from cliff import commandmanager [as 别名]
# 或者: from cliff.commandmanager import CommandManager [as 别名]
def __init__(self):
super(DemoApp, self).__init__(
description='cliff demo app',
version='0.1',
command_manager=CommandManager('cliff.demo'),
deferred_help=True,
)
示例10: _load_command
# 需要导入模块: from cliff import commandmanager [as 别名]
# 或者: from cliff.commandmanager import CommandManager [as 别名]
def _load_command(self, manager, command_name):
"""Load a command using an instance of a `CommandManager`."""
try:
# find_command expects the value of argv so split to emulate that
return manager.find_command(command_name.split())[0]
except ValueError:
raise self.error('"{}" is not a valid command in the "{}" '
'namespace'.format(
command_name, manager.namespace))
示例11: make_app
# 需要导入模块: from cliff import commandmanager [as 别名]
# 或者: from cliff.commandmanager import CommandManager [as 别名]
def make_app(**kwargs):
cmd_mgr = commandmanager.CommandManager('cliff.tests')
# Register a command that succeeds
cmd = mock.MagicMock(spec=command.Command)
command_inst = mock.MagicMock(spec=command.Command)
command_inst.run.return_value = 0
cmd.return_value = command_inst
cmd_mgr.add_command('mock', cmd)
# Register a command that fails
err_command = mock.Mock(name='err_command', spec=command.Command)
err_command_inst = mock.Mock(spec=command.Command)
err_command_inst.run = mock.Mock(
side_effect=RuntimeError('test exception')
)
err_command.return_value = err_command_inst
cmd_mgr.add_command('error', err_command)
app = application.App('testing command hooks',
'1',
cmd_mgr,
stderr=mock.Mock(), # suppress warning messages
**kwargs
)
return app
示例12: given_complete_command
# 需要导入模块: from cliff import commandmanager [as 别名]
# 或者: from cliff.commandmanager import CommandManager [as 别名]
def given_complete_command(self):
cmd_mgr = commandmanager.CommandManager('cliff.tests')
app = application.App('testing', '1', cmd_mgr, stdout=FakeStdout())
sot = complete.CompleteCommand(app, mock.Mock())
cmd_mgr.add_command('complete', complete.CompleteCommand)
return sot, app, cmd_mgr
示例13: test_option_parser_abbrev_issue
# 需要导入模块: from cliff import commandmanager [as 别名]
# 或者: from cliff.commandmanager import CommandManager [as 别名]
def test_option_parser_abbrev_issue(self):
class MyCommand(c_cmd.Command):
def get_parser(self, prog_name):
parser = super(MyCommand, self).get_parser(prog_name)
parser.add_argument("--end")
return parser
def take_action(self, parsed_args):
assert(parsed_args.end == '123')
class MyCommandManager(commandmanager.CommandManager):
def load_commands(self, namespace):
self.add_command("mycommand", MyCommand)
class MyApp(application.App):
def __init__(self):
super(MyApp, self).__init__(
description='testing',
version='0.1',
command_manager=MyCommandManager(None),
)
def build_option_parser(self, description, version):
parser = super(MyApp, self).build_option_parser(
description,
version,
argparse_kwargs={'allow_abbrev': False})
parser.add_argument('--endpoint')
return parser
app = MyApp()
# NOTE(jd) --debug is necessary so assert in take_action()
# raises correctly here
app.run(['--debug', 'mycommand', '--end', '123'])
示例14: test_fuzzy_no_commands
# 需要导入模块: from cliff import commandmanager [as 别名]
# 或者: from cliff.commandmanager import CommandManager [as 别名]
def test_fuzzy_no_commands(self):
cmd_mgr = commandmanager.CommandManager('cliff.fuzzy')
app = application.App('test', '1.0', cmd_mgr)
cmd_mgr.commands = {}
matches = app.get_fuzzy_matches('foo')
self.assertEqual([], matches)
示例15: test_fuzzy_common_prefix
# 需要导入模块: from cliff import commandmanager [as 别名]
# 或者: from cliff.commandmanager import CommandManager [as 别名]
def test_fuzzy_common_prefix(self):
# searched string is a prefix of all commands
cmd_mgr = commandmanager.CommandManager('cliff.fuzzy')
app = application.App('test', '1.0', cmd_mgr)
cmd_mgr.commands = {}
cmd_mgr.add_command('user list', test_utils.TestCommand)
cmd_mgr.add_command('user show', test_utils.TestCommand)
matches = app.get_fuzzy_matches('user')
self.assertEqual(['user list', 'user show'], matches)