Skip to content

Commit

Permalink
Merge pull request #1743 from grahamu/use-formatted-help
Browse files Browse the repository at this point in the history
Show formatted help with --help and -h options
  • Loading branch information
kennethreitz authored Mar 14, 2018
2 parents 52b6bb1 + 086f6d8 commit 2988018
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion pipenv/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,43 @@

CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])


class PipenvGroup(click.Group):
"""Custom Group class provides formatted main help"""

def get_help_option(self, ctx):
from . import core

"""Override for showing formatted main help via --help and -h options"""
help_options = self.get_help_option_names(ctx)
if not help_options or not self.add_help_option:
return

def show_help(ctx, param, value):
if value and not ctx.resilient_parsing:
if not ctx.invoked_subcommand:
# legit main help
click.echo(core.format_help(ctx.get_help()))
else:
# legit sub-command help
click.echo(ctx.get_help(), color=ctx.color)
ctx.exit()
return click.Option(
help_options,
is_flag=True,
is_eager=True,
expose_value=False,
callback=show_help,
help='Show this message and exit.')


def setup_verbose(ctx, param, value):
if value:
logging.getLogger('pip').setLevel(logging.INFO)
return value


@click.group(invoke_without_command=True, context_settings=CONTEXT_SETTINGS)
@click.group(cls=PipenvGroup, invoke_without_command=True, context_settings=CONTEXT_SETTINGS)
@click.option('--update', is_flag=True, default=False, help="Update Pipenv & pip to latest.")
@click.option('--where', is_flag=True, default=False, help="Output project home information.")
@click.option('--venv', is_flag=True, default=False, help="Output virtualenv information.")
Expand Down

0 comments on commit 2988018

Please sign in to comment.