From 9bf99935abf7c5e645c8eb14cac3a21a9090c01f Mon Sep 17 00:00:00 2001 From: Michael Joseph Date: Fri, 23 Oct 2015 17:51:10 +0200 Subject: [PATCH 1/3] Support -h for help --- cookiecutter/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cookiecutter/cli.py b/cookiecutter/cli.py index 6f53e24e7..75918bb74 100755 --- a/cookiecutter/cli.py +++ b/cookiecutter/cli.py @@ -30,7 +30,7 @@ def version_msg(): return message.format(location, python_version) -@click.command() +@click.command(context_settings=dict(help_option_names=[u'-h', u'--help'])) @click.version_option(__version__, u'-V', u'--version', message=version_msg()) @click.argument(u'template') @click.option( From 0cbf942807520061aff1dd04ba2c152a02c8ac32 Mon Sep 17 00:00:00 2001 From: Michael Joseph Date: Fri, 23 Oct 2015 17:56:23 +0200 Subject: [PATCH 2/3] Support "cookiecutter help" --- cookiecutter/cli.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cookiecutter/cli.py b/cookiecutter/cli.py index 75918bb74..7d6835076 100755 --- a/cookiecutter/cli.py +++ b/cookiecutter/cli.py @@ -75,6 +75,13 @@ def main(template, no_input, checkout, verbose, replay, overwrite_if_exists, ) try: + + # If you _need_ to support a local template in a directory + # called 'help', use a qualified path to the directory. + if template == u'help': + click.echo(click.get_current_context().get_help()) + sys.exit(0) + cookiecutter( template, checkout, no_input, replay=replay, From 61af6c5ea0ad195b62df1a683ed5057a60c76059 Mon Sep 17 00:00:00 2001 From: Michael Joseph Date: Fri, 23 Oct 2015 17:56:38 +0200 Subject: [PATCH 3/3] Test help flags --- tests/test_cli.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_cli.py b/tests/test_cli.py index 60f879504..0bc49bbdc 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -203,3 +203,14 @@ def test_cli_output_dir(mocker, output_dir_flag, output_dir): overwrite_if_exists=False, output_dir=output_dir ) + + +@pytest.fixture(params=['-h', '--help', 'help']) +def help_cli_flag(request): + return request.param + + +def test_cli_help(help_cli_flag): + result = runner.invoke(main, [help_cli_flag]) + assert result.exit_code == 0 + assert result.output.startswith('Usage')