當前位置: 首頁>>代碼示例>>Python>>正文


Python click.pass_context方法代碼示例

本文整理匯總了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 
開發者ID:linkedin,項目名稱:fossor,代碼行數:27,代碼來源:cli.py

示例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 
開發者ID:hexylena,項目名稱:argparse2tool,代碼行數:21,代碼來源:test_click2cwl.py

示例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 
開發者ID:tencentyun,項目名稱:scfcli,代碼行數:22,代碼來源:generate_event_action.py

示例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 
開發者ID:psss,項目名稱:tmt,代碼行數:20,代碼來源:__init__.py

示例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 
開發者ID:psss,項目名稱:tmt,代碼行數:20,代碼來源:__init__.py

示例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 
開發者ID:psss,項目名稱:tmt,代碼行數:20,代碼來源:__init__.py

示例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 
開發者ID:psss,項目名稱:tmt,代碼行數:20,代碼來源:__init__.py

示例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 
開發者ID:psss,項目名稱:tmt,代碼行數:20,代碼來源:__init__.py

示例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) 
開發者ID:xeroc,項目名稱:stakemachine,代碼行數:18,代碼來源:ui.py

示例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() 
開發者ID:NetworkAutomation,項目名稱:jaide,代碼行數:22,代碼來源:cli.py

示例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() 
開發者ID:NetworkAutomation,項目名稱:jaide,代碼行數:26,代碼來源:cli.py

示例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() 
開發者ID:NetworkAutomation,項目名稱:jaide,代碼行數:26,代碼來源:cli.py

示例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 
開發者ID:Mirantis,項目名稱:ceph-lcm,代碼行數:20,代碼來源:decorators.py

示例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) 
開發者ID:pgjones,項目名稱:quart,代碼行數:16,代碼來源:cli.py

示例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)) 
開發者ID:click-contrib,項目名稱:click-repl,代碼行數:5,代碼來源:__init__.py


注:本文中的click.pass_context方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。