当前位置: 首页>>代码示例>>Python>>正文


Python click.Option方法代码示例

本文整理汇总了Python中click.Option方法的典型用法代码示例。如果您正苦于以下问题:Python click.Option方法的具体用法?Python click.Option怎么用?Python click.Option使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在click的用法示例。


在下文中一共展示了click.Option方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: cli_option_traceback

# 需要导入模块: import click [as 别名]
# 或者: from click import Option [as 别名]
def cli_option_traceback(func):
    """Decorator for adding a pre-defined, reusable CLI option `--traceback`."""

    # noinspection PyUnusedLocal
    def _callback(ctx: click.Context, param: click.Option, value: bool):
        ctx_obj = ctx.ensure_object(dict)
        if ctx_obj is not None:
            ctx_obj["traceback"] = value
        return value

    return click.option(
        '--traceback',
        is_flag=True,
        help="Enable tracing back errors by dumping the Python call stack. "
             "Pass as very first option to also trace back error during command-line validation.",
        callback=_callback)(func) 
开发者ID:dcs4cop,项目名称:xcube,代码行数:18,代码来源:common.py

示例2: command

# 需要导入模块: import click [as 别名]
# 或者: from click import Option [as 别名]
def command(name=None, cls=None, **attrs):
    """
    Commands are the basic building block of command line interfaces in
    Click.  A basic command handles command line parsing and might dispatch
    more parsing to commands nested below it.

    :param name: the name of the command to use unless a group overrides it.
    :param context_settings: an optional dictionary with defaults that are
                             passed to the context object.
    :param params: the parameters to register with this command.  This can
                   be either :class:`Option` or :class:`Argument` objects.
    :param help: the help string to use for this command.
    :param epilog: like the help string but it's printed at the end of the
                   help page after everything else.
    :param short_help: the short help to use for this command.  This is
                       shown on the command listing of the parent command.
    :param add_help_option: by default each command registers a ``--help``
                            option.  This can be disabled by this parameter.
    :param options_metavar: The options metavar to display in the usage.
                            Defaults to ``[OPTIONS]``.
    :param args_before_options: Whether or not to display the options
                                        metavar before the arguments.
                                        Defaults to False.
    """
    return click.command(name=name, cls=cls or Command, **attrs) 
开发者ID:briancappello,项目名称:flask-unchained,代码行数:27,代码来源:click.py

示例3: extract_option_object

# 需要导入模块: import click [as 别名]
# 或者: from click import Option [as 别名]
def extract_option_object(option):
    """Convert a click.option call into a click.Option object.

    Parameters
    ----------
    option : decorator
        A click.option decorator.

    Returns
    -------
    option_object : click.Option
        The option object that this decorator will create.
    """

    @option
    def opt():
        pass

    return opt.__click_params__[0] 
开发者ID:enigmampc,项目名称:catalyst,代码行数:21,代码来源:__main__.py

示例4: sanitize_version

# 需要导入模块: import click [as 别名]
# 或者: from click import Option [as 别名]
def sanitize_version(_ctx: Optional[click.Context],
                     _param: Optional[Union[click.Option, click.Parameter]],
                     value: str
                     ) -> str:
    """Sanitize a version number by stripping git tag ref and leading "v".

    To be used as the callback of a click option or parameter.

    Args:
        ctx: Click context object.
        param: The click option or parameter the callback is being used with.
        value: Value passed to the option or parameter from the CLI.

    Returns:
        str: The SemVer version number.

    """
    version = value.replace('refs/tags/', '')  # strip git ref
    if version.startswith('v'):  # strip leading "v"
        version = version[1:]
    if VersionInfo.isvalid(version):  # valid SemVer
        return version
    raise ValueError(f'version of "{version}" does not follow SemVer') 
开发者ID:onicagroup,项目名称:runway,代码行数:25,代码来源:update_urls.py

示例5: usage_example_option

# 需要导入模块: import click [as 别名]
# 或者: from click import Option [as 别名]
def usage_example_option(action):
    import click
    from q2cli.core.usage import examples

    def callback(ctx, param, value):
        if not value or ctx.resilient_parsing:
            return

        action = ctx.command._get_action()

        for line in examples(action):
            click.secho(line)

        ctx.exit()

    return click.Option(['--examples'], is_flag=True, expose_value=False,
                        is_eager=True, callback=callback,
                        help='Show usage examples and exit.') 
开发者ID:qiime2,项目名称:q2cli,代码行数:20,代码来源:util.py

示例6: __init__

# 需要导入模块: import click [as 别名]
# 或者: from click import Option [as 别名]
def __init__(self, plugin, name, *args, **kwargs):
        import q2cli.util

        # the cli currently doesn't differentiate between methods
        # and visualizers, it treats them generically as Actions
        self._plugin = plugin
        self._action_lookup = {q2cli.util.to_cli_name(id): a for id, a in
                               plugin['actions'].items()}

        support = 'Getting user support: %s' % plugin['user_support_text']
        website = 'Plugin website: %s' % plugin['website']
        description = 'Description: %s' % plugin['description']
        help_ = '\n\n'.join([description, website, support])

        params = [
            click.Option(('--version',), is_flag=True, expose_value=False,
                         is_eager=True, callback=self._get_version,
                         help='Show the version and exit.'),
            q2cli.util.citations_option(self._get_citation_records)
        ]

        super().__init__(name, *args, short_help=plugin['short_description'],
                         help=help_, params=params, **kwargs) 
开发者ID:qiime2,项目名称:q2cli,代码行数:25,代码来源:commands.py

示例7: get_command

# 需要导入模块: import click [as 别名]
# 或者: from click import Option [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

示例8: get_choices

# 需要导入模块: import click [as 别名]
# 或者: from click import Option [as 别名]
def get_choices(cli, prog_name, args, incomplete):
        """
        This is identical to click._bashcomplete:get_choices in click 6.4+
        """
        ctx = resolve_ctx(cli, prog_name, args)

        if ctx is None:
            return

        choices = []
        if incomplete and not incomplete[:1].isalnum():
            for param in ctx.command.params:
                if not isinstance(param, click.Option):
                    continue
                choices.extend(param.opts)
                choices.extend(param.secondary_opts)
        elif isinstance(ctx.command, click.MultiCommand):
            choices.extend(ctx.command.list_commands(ctx))

        for item in choices:
            if item.startswith(incomplete):
                yield item 
开发者ID:clarkperkins,项目名称:click-shell,代码行数:24,代码来源:_compat.py

示例9: generate_man_page

# 需要导入模块: import click [as 别名]
# 或者: from click import Option [as 别名]
def generate_man_page(ctx, version=None):
    """
    Generate documentation for the given command.

    :param click.Context ctx: the click context for the
                              cli application.

    :rtype: str
    :returns: the generate man page from the given click Context.
    """
    # Create man page with the details from the given context
    man_page = ManPage(ctx.command_path)
    man_page.version = version
    man_page.short_help = ctx.command.get_short_help_str()
    man_page.description = ctx.command.help
    man_page.synopsis = ' '.join(ctx.command.collect_usage_pieces(ctx))
    man_page.options = [x.get_help_record(ctx) for x in ctx.command.params if isinstance(x, click.Option)]
    commands = getattr(ctx.command, 'commands', None)
    if commands:
        man_page.commands = [
            (k, v.get_short_help_str()) for k, v in commands.items()
        ]

    return str(man_page) 
开发者ID:click-contrib,项目名称:click-man,代码行数:26,代码来源:core.py

示例10: push_params

# 需要导入模块: import click [as 别名]
# 或者: from click import Option [as 别名]
def push_params(fn):
    click_util.append_params(
        fn,
        [
            remote_support.remote_arg,
            runs_support.runs_arg,
            runs_support.all_filters,
            click.Option(
                ("-n", "--delete",),
                help="Delete remote files missing locally.",
                is_flag=True,
            ),
            click.Option(
                ("-y", "--yes"), help="Do not prompt before copying.", is_flag=True
            ),
        ],
    )
    return fn 
开发者ID:guildai,项目名称:guildai,代码行数:20,代码来源:runs_push.py

示例11: host_and_port_options

# 需要导入模块: import click [as 别名]
# 或者: from click import Option [as 别名]
def host_and_port_options(fn):
    click_util.append_params(
        fn,
        [
            click.Option(
                ("-h", "--host",),
                metavar="HOST",
                help="Name of host interface to listen on.",
            ),
            click.Option(
                ("-p", "--port",),
                metavar="PORT",
                help="Port to listen on.",
                type=click.IntRange(0, 65535),
            ),
        ],
    )
    return fn 
开发者ID:guildai,项目名称:guildai,代码行数:20,代码来源:server_support.py

示例12: remote_option

# 需要导入模块: import click [as 别名]
# 或者: from click import Option [as 别名]
def remote_option(help):
    """`REMOTE` is the name of a configured remote. Use ``guild remotes``
    to list available remotes.

    For information on configuring remotes, see ``guild remotes
    --help``.

    """
    assert isinstance(help, str), "@remote_option must be called with help"

    def wrapper(fn):
        click_util.append_params(
            fn, [click.Option(("-r", "--remote"), metavar="REMOTE", help=help),]
        )
        return fn

    return wrapper 
开发者ID:guildai,项目名称:guildai,代码行数:19,代码来源:remote_support.py

示例13: runs_stop_params

# 需要导入模块: import click [as 别名]
# 或者: from click import Option [as 别名]
def runs_stop_params(fn):
    click_util.append_params(
        fn,
        [
            runs_support.runs_arg,
            runs_support.op_and_label_filters,
            runs_support.time_filters,
            runs_support.sourcecode_digest_filters,
            remote_support.remote_option("Stop remote runs."),
            click.Option(
                ("-y", "--yes"), help="Do not prompt before stopping.", is_flag=True
            ),
            click.Option(
                ("-n", "--no-wait"),
                help="Don't wait for remote runs to stop.",
                is_flag=True,
            ),
        ],
    )
    return fn 
开发者ID:guildai,项目名称:guildai,代码行数:22,代码来源:runs_stop.py

示例14: sourcecode_digest_filters

# 需要导入模块: import click [as 别名]
# 或者: from click import Option [as 别名]
def sourcecode_digest_filters(fn):
    """### Filter by Source Code Digest

    To show runs for a specific source code digest, use `-g` or
    `--digest` with a complete or partial digest value.

    """
    click_util.append_params(
        fn,
        [
            click.Option(
                ("-D", "--digest",),
                metavar="VAL",
                help=("Filter only runs with a matching source code digest."),
            )
        ],
    )
    return fn 
开发者ID:guildai,项目名称:guildai,代码行数:20,代码来源:runs_support.py

示例15: export_params

# 需要导入模块: import click [as 别名]
# 或者: from click import Option [as 别名]
def export_params(fn):
    click_util.append_params(
        fn,
        [
            runs_support.runs_arg,
            click.Argument(("location",)),
            click.Option(
                ("-m", "--move"),
                help="Move exported runs rather than copy.",
                is_flag=True,
            ),
            click.Option(
                ("-r", "--copy-resources",),
                help="Copy resources for each exported run.",
                is_flag=True,
            ),
            runs_support.all_filters,
            click.Option(
                ("-y", "--yes"), help="Do not prompt before exporting.", is_flag=True
            ),
        ],
    )
    return fn 
开发者ID:guildai,项目名称:guildai,代码行数:25,代码来源:runs_export.py


注:本文中的click.Option方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。