本文整理汇总了Python中click.pass_context方法的典型用法代码示例。如果您正苦于以下问题:Python click.pass_context方法的具体用法?Python click.pass_context怎么用?Python click.pass_context使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类click
的用法示例。
在下文中一共展示了click.pass_context方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fossor_cli_flags
# 需要导入模块: import click [as 别名]
# 或者: from click import pass_context [as 别名]
def fossor_cli_flags(f):
'''Add default Fossor CLI flags'''
# Flags will appear in reverse order of how they are listed here:
f = add_dynamic_args(f) # Must be applied after all other click options since this requires click's context object to be passed
# Add normal flags
csv_list = CsvList()
f = click.option('--black-list', 'blacklist', type=csv_list, help='Do not run these plugins.')(f)
f = click.option('--white-list', 'whitelist', type=csv_list, help='Only run these plugins.')(f)
f = click.option('--truncate/--no-truncate', 'truncate', show_default=True, default=True, is_flag=True)(f)
f = click.option('-v', '--verbose', is_flag=True)(f)
f = click.option('-d', '--debug', is_flag=True, callback=setup_logging)(f)
f = click.option('-t', '--time-out', 'timeout', show_default=True, default=600, help='Default timeout for plugins.')(f)
f = click.option('--end-time', callback=set_end_time, help='Plugins may optionally implement and use this. Defaults to now.')(f)
f = click.option('--start-time', callback=set_start_time, help='Plugins may optionally implement and use this.')(f)
f = click.option('-r', '--report', type=click.STRING, show_default=True, default='StdOut', help='Report Plugin to run.')(f)
f = click.option('--hours', type=click.INT, default=24, show_default=True, callback=set_relative_start_time,
help='Sets start-time to X hours ago. Plugins may optionally implement and use this.')(f)
f = click.option('--plugin-dir', default=default_plugin_dir, show_default=True, help=f'Import all plugins from this directory.')(f)
f = click.option('-p', '--pid', type=click.INT, help='Pid to investigate.')(f)
# Required for parsing dynamics arguments
f = click.pass_context(f)
f = click.command(context_settings=dict(ignore_unknown_options=True, allow_extra_args=True, help_option_names=['-h', '--help']))(f)
return f
示例2: test_subparser
# 需要导入模块: import click [as 别名]
# 或者: from click import pass_context [as 别名]
def test_subparser(self):
"""
Tests if tools with subparsers run without errors
"""
@click.group()
@click.pass_context
@click.option('--debug', default=False)
def cli(debug):
pass
@cli.command()
@click.option('-s', '--some-option')
def sync(some_option):
pass
@cli.command()
@click.option('-o', '--some-other-option')
def async(some_option):
pass
示例3: get_command
# 需要导入模块: import click [as 别名]
# 或者: from click import pass_context [as 别名]
def get_command(self, ctx, cmd):
if cmd not in self.srv_info:
return None
params = []
for param in self.srv_info[cmd][self.PARAMS].keys():
default = self.srv_info[cmd][self.PARAMS][param]["default"]
params.append(click.Option(
["--{}".format(param)],
default=default,
help="Specify the {}, default is {}".format(param, default)
))
cbfun = click.pass_context(self.action)
cmd = click.Command(name=cmd,
short_help=self.srv_info[cmd]["help"],
params=params, callback=cbfun)
return cmd
示例4: base_command
# 需要导入模块: import click [as 别名]
# 或者: from click import pass_context [as 别名]
def base_command(cls, method_class=None, usage=None):
""" Create base click command (common for all finish plugins) """
# Prepare general usage message for the step
if method_class:
usage = Finish.usage(method_overview=usage)
# Create the command
@click.command(cls=method_class, help=usage)
@click.pass_context
@click.option(
'-h', '--how', metavar='METHOD',
help='Use specified method for finishing tasks.')
def finish(context, **kwargs):
context.obj.steps.add('finish')
Finish._save_context(context)
return finish
示例5: base_command
# 需要导入模块: import click [as 别名]
# 或者: from click import pass_context [as 别名]
def base_command(cls, method_class=None, usage=None):
""" Create base click command (common for all provision plugins) """
# Prepare general usage message for the step
if method_class:
usage = Provision.usage(method_overview=usage)
# Create the command
@click.command(cls=method_class, help=usage)
@click.pass_context
@click.option(
'-h', '--how', metavar='METHOD',
help='Use specified method for provisioning.')
def provision(context, **kwargs):
context.obj.steps.add('provision')
Provision._save_context(context)
return provision
示例6: base_command
# 需要导入模块: import click [as 别名]
# 或者: from click import pass_context [as 别名]
def base_command(cls, method_class=None, usage=None):
""" Create base click command (common for all prepare plugins) """
# Prepare general usage message for the step
if method_class:
usage = Prepare.usage(method_overview=usage)
# Create the command
@click.command(cls=method_class, help=usage)
@click.pass_context
@click.option(
'-h', '--how', metavar='METHOD',
help='Use specified method for environment preparation.')
def prepare(context, **kwargs):
context.obj.steps.add('prepare')
Prepare._save_context(context)
return prepare
示例7: base_command
# 需要导入模块: import click [as 别名]
# 或者: from click import pass_context [as 别名]
def base_command(cls, method_class=None, usage=None):
""" Create base click command (common for all report plugins) """
# Prepare general usage message for the step
if method_class:
usage = Report.usage(method_overview=usage)
# Create the command
@click.command(cls=method_class, help=usage)
@click.pass_context
@click.option(
'-h', '--how', metavar='METHOD',
help='Use specified method for results reporting.')
def report(context, **kwargs):
context.obj.steps.add('report')
Report._save_context(context)
return report
示例8: base_command
# 需要导入模块: import click [as 别名]
# 或者: from click import pass_context [as 别名]
def base_command(cls, method_class=None, usage=None):
""" Create base click command (common for all discover plugins) """
# Prepare general usage message for the step
if method_class:
usage = Discover.usage(method_overview=usage)
# Create the command
@click.command(cls=method_class, help=usage)
@click.pass_context
@click.option(
'-h', '--how', metavar='METHOD',
help='Use specified method to discover tests.')
def discover(context, **kwargs):
context.obj.steps.add('discover')
Discover._save_context(context)
return discover
示例9: unlock
# 需要导入模块: import click [as 别名]
# 或者: from click import pass_context [as 别名]
def unlock(f):
@click.pass_context
def new_func(ctx, *args, **kwargs):
if not ctx.obj.get("unsigned", False):
if ctx.bitshares.wallet.created():
if "UNLOCK" in os.environ:
pwd = os.environ["UNLOCK"]
else:
pwd = click.prompt("Current Wallet Passphrase", hide_input=True)
ctx.bitshares.wallet.unlock(pwd)
else:
click.echo("No wallet installed yet. Creating ...")
pwd = click.prompt("Wallet Encryption Passphrase", hide_input=True, confirmation_prompt=True)
ctx.bitshares.wallet.create(pwd)
return ctx.invoke(f, *args, **kwargs)
return update_wrapper(new_func, f)
示例10: device_info
# 需要导入模块: import click [as 别名]
# 或者: from click import pass_context [as 别名]
def device_info(ctx):
""" Get basic device information.
@param ctx: The click context paramter, for receiving the object dictionary
| being manipulated by other previous functions. Needed by any
| function with the @click.pass_context decorator.
@type ctx: click.Context
"""
mp_pool = multiprocessing.Pool(multiprocessing.cpu_count() * 2)
for ip in ctx.obj['hosts']:
mp_pool.apply_async(wrap.open_connection, args=(ip,
ctx.obj['conn']['username'],
ctx.obj['conn']['password'],
wrap.device_info, [],
ctx.obj['out'],
ctx.obj['conn']['connect_timeout'],
ctx.obj['conn']['session_timeout'],
ctx.obj['conn']['port']), callback=write_out)
mp_pool.close()
mp_pool.join()
示例11: health_check
# 需要导入模块: import click [as 别名]
# 或者: from click import pass_context [as 别名]
def health_check(ctx):
""" Get alarm and device health information.
@param ctx: The click context paramter, for receiving the object dictionary
| being manipulated by other previous functions. Needed by any
| function with the @click.pass_context decorator.
@type ctx: click.Context
@returns: None. Functions part of click relating to the command group
| 'main' do not return anything. Click handles passing context
| between the functions and maintaing command order and chaining.
"""
mp_pool = multiprocessing.Pool(multiprocessing.cpu_count() * 2)
for ip in ctx.obj['hosts']:
mp_pool.apply_async(wrap.open_connection, args=(ip,
ctx.obj['conn']['username'],
ctx.obj['conn']['password'],
wrap.health_check, [],
ctx.obj['out'],
ctx.obj['conn']['connect_timeout'],
ctx.obj['conn']['session_timeout'],
ctx.obj['conn']['port']), callback=write_out)
mp_pool.close()
mp_pool.join()
示例12: interface_errors
# 需要导入模块: import click [as 别名]
# 或者: from click import pass_context [as 别名]
def interface_errors(ctx):
""" Get any interface errors from the device.
@param ctx: The click context paramter, for receiving the object dictionary
| being manipulated by other previous functions. Needed by any
| function with the @click.pass_context decorator.
@type ctx: click.Context
@returns: None. Functions part of click relating to the command group
| 'main' do not return anything. Click handles passing context
| between the functions and maintaing command order and chaining.
"""
mp_pool = multiprocessing.Pool(multiprocessing.cpu_count() * 2)
for ip in ctx.obj['hosts']:
mp_pool.apply_async(wrap.open_connection, args=(ip,
ctx.obj['conn']['username'],
ctx.obj['conn']['password'],
wrap.interface_errors, [],
ctx.obj['out'],
ctx.obj['conn']['connect_timeout'],
ctx.obj['conn']['session_timeout'],
ctx.obj['conn']['port']), callback=write_out)
mp_pool.close()
mp_pool.join()
示例13: catch_errors
# 需要导入模块: import click [as 别名]
# 或者: from click import pass_context [as 别名]
def catch_errors(func):
"""Decorator which catches all errors and tries to print them."""
@six.wraps(func)
@click.pass_context
def decorator(ctx, *args, **kwargs):
try:
return func(*args, **kwargs)
except exceptions.DecapodAPIError as exc:
utils.format_output_json(ctx, exc.json, True)
except exceptions.DecapodError as exc:
click.echo(six.text_type(exc), err=True)
finally:
ctx.close()
ctx.exit(os.EX_SOFTWARE)
return decorator
示例14: with_appcontext
# 需要导入模块: import click [as 别名]
# 或者: from click import pass_context [as 别名]
def with_appcontext(fn: Optional[Callable] = None) -> Callable:
# decorator was used with parenthesis
if fn is None:
return with_appcontext
@click.pass_context
def decorator(__ctx: click.Context, *args: Any, **kwargs: Any) -> Any:
async def _inner() -> Any:
async with __ctx.ensure_object(ScriptInfo).load_app().app_context():
return __ctx.invoke(fn, *args, **kwargs)
return asyncio.run(_inner())
return functools.update_wrapper(decorator, fn)
示例15: register_repl
# 需要导入模块: import click [as 别名]
# 或者: from click import pass_context [as 别名]
def register_repl(group, name="repl"):
"""Register :func:`repl()` as sub-command *name* of *group*."""
group.command(name=name)(click.pass_context(repl))