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


Python click.help_option方法代碼示例

本文整理匯總了Python中click.help_option方法的典型用法代碼示例。如果您正苦於以下問題:Python click.help_option方法的具體用法?Python click.help_option怎麽用?Python click.help_option使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在click的用法示例。


在下文中一共展示了click.help_option方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: extended_help_option

# 需要導入模塊: import click [as 別名]
# 或者: from click import help_option [as 別名]
def extended_help_option(extended_help=None, *param_decls, **attrs):
    """
    Based on the click.help_option code.

    Adds a ``--extended-help`` option which immediately ends the program
    printing out the extended extended-help page. Defaults to using the
    callback's doc string, but can be given an explicit value as well.

    This is intended for use as a decorator on a command to provide a 3rd level
    of help verbosity suitable for use as a manpage (though not formatted as such explicitly).

    Like :func:`version_option`, this is implemented as eager option that
    prints in the callback and exits.

    All arguments are forwarded to :func:`option`.
    """

    def decorator(f):
        def callback(ctx, param, value):
            if value and not ctx.resilient_parsing:
                if not extended_help:
                    ctx.command.help = ctx.command.callback.__doc__
                    click.echo(ctx.get_help(), color=ctx.color)
                else:
                    ctx.command.help = extended_help
                    click.echo(ctx.get_help(), color=ctx.color)
                ctx.exit()

        attrs.setdefault('is_flag', True)
        attrs.setdefault('expose_value', False)
        attrs.setdefault('help', 'Show extended help content, similar to manpage, and exit.')
        attrs.setdefault('is_eager', True)
        attrs['callback'] = callback
        return click.option(*(param_decls or ('--extended-help',)), **attrs)(f)

    return decorator 
開發者ID:anchore,項目名稱:anchore,代碼行數:38,代碼來源:common.py

示例2: add_help_option

# 需要導入模塊: import click [as 別名]
# 或者: from click import help_option [as 別名]
def add_help_option(self):
    """Add a help option to the command."""
    click.help_option(*('--help', '-h'))(self) 
開發者ID:Gandi,項目名稱:gandi.cli,代碼行數:5,代碼來源:cli.py

示例3: common_options

# 需要導入模塊: import click [as 別名]
# 或者: from click import help_option [as 別名]
def common_options(*args, **kwargs):
    """
    This is a multi-purpose decorator for applying a "base" set of options
    shared by all commands.
    It can be applied either directly, or given keyword arguments.

    Usage:

    >>> @common_options
    >>> def mycommand(abc, xyz):
    >>>     ...

    or

    >>> @common_options(disable_options=["format"])
    >>> def mycommand(abc, xyz):
    >>>     ...

    to disable use of `--format`
    """

    disable_opts = kwargs.get("disable_options", [])

    def decorate(f, **kwargs):
        """
        Work of actually decorating a function -- wrapped in here because we
        want to dispatch depending on how `common_options` is invoked
        """
        f = version_option(f)
        f = debug_option(f)
        f = verbose_option(f)
        f = click.help_option("-h", "--help")(f)

        # if the format option is being allowed, it needs to be applied to `f`
        if "format" not in disable_opts:
            f = format_option(f)

        # if the --map-http-status option is being allowed, ...
        if "map_http_status" not in disable_opts:
            f = map_http_status_option(f)

        return f

    return detect_and_decorate(decorate, args, kwargs) 
開發者ID:globus,項目名稱:globus-cli,代碼行數:46,代碼來源:shared_options.py


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