當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。