Python click.help_option() Examples

The following are 3 code examples of click.help_option(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module click , or try the search function .
Example #1
Source File: common.py    From anchore with Apache License 2.0 5 votes vote down vote up
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 
Example #2
Source File: cli.py    From gandi.cli with GNU General Public License v3.0 5 votes vote down vote up
def add_help_option(self):
    """Add a help option to the command."""
    click.help_option(*('--help', '-h'))(self) 
Example #3
Source File: shared_options.py    From globus-cli with Apache License 2.0 4 votes vote down vote up
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)