本文整理汇总了Python中cliff.command.Command方法的典型用法代码示例。如果您正苦于以下问题:Python command.Command方法的具体用法?Python command.Command怎么用?Python command.Command使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cliff.command
的用法示例。
在下文中一共展示了command.Command方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_parser
# 需要导入模块: from cliff import command [as 别名]
# 或者: from cliff.command import Command [as 别名]
def get_parser(self, prog_name):
parser = super(CompleteCommand, self).get_parser(prog_name)
parser.add_argument(
"--name",
default=None,
metavar='<command_name>',
help="Command name to support with command completion"
)
parser.add_argument(
"--shell",
default='bash',
metavar='<shell>',
choices=sorted(self._formatters.names()),
help="Shell being used. Use none for data only (default: bash)"
)
return parser
示例2: __init__
# 需要导入模块: from cliff import command [as 别名]
# 或者: from cliff.command import Command [as 别名]
def __init__(self,
app,
app_args,
wrapper: BaseFeatureLearningWrapper,
default_batch_size: int = 500):
"""
Creates and initializes a new GenerateBaseCommand with the specified parameters.
Parameters
----------
app
Pass through to `Command`
app_args
Pass through to `Command`
wrapper: FeatureLearningWrapper
The feature learning wrapper used for generating features
default_batch_size: int
Default batch size
"""
super().__init__(app, app_args)
self._wrapper = wrapper
self._default_batch_size = default_batch_size
示例3: __init__
# 需要导入模块: from cliff import command [as 别名]
# 或者: from cliff.command import Command [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
)
示例4: get_header
# 需要导入模块: from cliff import command [as 别名]
# 或者: from cliff.command import Command [as 别名]
def get_header(self):
return ('_' + self.escaped_name + """()
{
local cur prev words
COMPREPLY=()
_get_comp_words_by_ref -n : cur prev words
# Command data:
""")
示例5: make_app
# 需要导入模块: from cliff import command [as 别名]
# 或者: from cliff.command import Command [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
示例6: make_app
# 需要导入模块: from cliff import command [as 别名]
# 或者: from cliff.command import Command [as 别名]
def make_app(**kwargs):
cmd_mgr = commandmanager.CommandManager('cliff.tests')
# Register a command that succeeds
command = mock.MagicMock(spec=c_cmd.Command)
command_inst = mock.MagicMock(spec=c_cmd.Command)
command_inst.run.return_value = 0
command.return_value = command_inst
cmd_mgr.add_command('mock', command)
# Register a command that fails
err_command = mock.Mock(name='err_command', spec=c_cmd.Command)
err_command_inst = mock.Mock(spec=c_cmd.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 interactive mode',
'1',
cmd_mgr,
stderr=mock.Mock(), # suppress warning messages
**kwargs
)
return app, command
示例7: test_option_parser_abbrev_issue
# 需要导入模块: from cliff import command [as 别名]
# 或者: from cliff.command import Command [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'])
示例8: run
# 需要导入模块: from cliff import command [as 别名]
# 或者: from cliff.command import Command [as 别名]
def run(self, parsed_args):
self.log.debug('run(%s)', parsed_args)
return super(Command, self).run(parsed_args)
示例9: __init__
# 需要导入模块: from cliff import command [as 别名]
# 或者: from cliff.command import Command [as 别名]
def __init__(self):
# 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
# Slight change to the meaning of --debug
self.DEFAULT_DEBUG_VALUE = None
self.DEFAULT_DEBUG_HELP = 'Set debug logging and traceback on errors.'
super(ECLClient, self).__init__(
description=__doc__.strip(),
version=eclcli.__version__,
command_manager=commandmanager.CommandManager('ecl.cli'),
deferred_help=True)
del self.command_manager.commands['complete']
# del self.command_manager.commands['help']
self.api_version = {}
# Until we have command line arguments parsed, dump any stack traces
self.dump_stack_trace = True
# Assume TLS host certificate verification is enabled
self.verify = True
self.client_manager = None
self.command_options = None
self.do_profile = False
示例10: get_parser
# 需要导入模块: from cliff import command [as 别名]
# 或者: from cliff.command import Command [as 别名]
def get_parser(self, prog_name):
parser = super(SeedHypervisorHostCommandRun, self).get_parser(
prog_name)
group = parser.add_argument_group("Host Command Run")
group.add_argument("--command", required=True,
help="Command to run (required).")
return parser
示例11: __init__
# 需要导入模块: from cliff import command [as 别名]
# 或者: from cliff.command import Command [as 别名]
def __init__(self,
app,
app_args,
default_batch_size: int = 64,
default_num_epochs: int = 10,
default_learning_rate: float = 0.001,
default_run_name: Path = Path("./test-run")):
"""
Create and initialize a new TrainBaseCommand with the specified parameters.
Parameters
----------
app
Pass through to `Command`
app_args
Pass through to `Command`
default_batch_size: int
Default batch size
default_num_epochs: int
Default number of epochs
default_learning_rate: float
Default learning rate
default_run_name: Path
Default run name
"""
super().__init__(app, app_args)
self.default_batch_size = default_batch_size
self.default_num_epochs = default_num_epochs
self.default_learning_rate = default_learning_rate
self.default_run_name = default_run_name
self.model_filename = None
self.record_files = None
self.feature_shape = None
self.num_instances = None
示例12: clean_up
# 需要导入模块: from cliff import command [as 别名]
# 或者: from cliff.command import Command [as 别名]
def clean_up(self, cmd, result, err):
# type: (Command, int, Optional[Exception]) -> None
if isinstance(err, CLIUsageError):
self.parser.print_help()