Skip to content

Commit

Permalink
For #706, this replaces click with typer
Browse files Browse the repository at this point in the history
  • Loading branch information
pydanny committed Apr 6, 2024
1 parent 44f31b0 commit 755b6b5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"use_black": "n",
"use_pypi_deployment_with_travis": "y",
"add_pyup_badge": "n",
"command_line_interface": ["Click", "Argparse", "No command-line interface"],
"command_line_interface": ["Typer", "Argparse", "No command-line interface"],
"create_author_file": "y",
"open_source_license": ["MIT license", "BSD license", "ISC license", "Apache Software License 2.0", "GNU General Public License v3", "Not open source"],
"__gh_slug": "{{ cookiecutter.github_username }}/{{ cookiecutter.project_slug }}"
Expand Down
2 changes: 1 addition & 1 deletion {{cookiecutter.project_slug}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ classifiers = [
]
license = {text = "{{cookiecutter.open_source_license}}"}
dependencies = [
{% if cookiecutter.command_line_interface.lower() == "yes" -%}"rich",
{% if cookiecutter.command_line_interface.lower() == "typer" -%}
"typer"
{%- endif %}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
"""Console script for {{cookiecutter.project_slug}}."""
import {{cookiecutter.project_slug}}
{%- if cookiecutter.command_line_interface|lower == 'typer' %}
import typer

app = typer.Typer()


@app.command()
def goodbye(name: str, formal: bool = False):
if formal:
print(f"Goodbye Ms. {name}. Have a good day.")
else:
print(f"Bye {name}!")


if __name__ == "__main__":
app()
{%- endif %}
{%- if cookiecutter.command_line_interface|lower == 'argparse' %}
import argparse
{%- endif %}
import sys
{%- if cookiecutter.command_line_interface|lower == 'click' %}
import click
{%- endif %}

{% if cookiecutter.command_line_interface|lower == 'click' %}
@click.command()
def main(args=None):
"""Console script for {{cookiecutter.project_slug}}."""
click.echo("Replace this message by putting your code into "
"{{cookiecutter.project_slug}}.cli.main")
click.echo("See click documentation at https://click.palletsprojects.com/")
return 0
{%- endif %}
{%- if cookiecutter.command_line_interface|lower == 'argparse' %}
def main():
"""Console script for {{cookiecutter.project_slug}}."""
parser = argparse.ArgumentParser()
Expand All @@ -28,8 +31,7 @@ def main():
print("Replace this message by putting your code into "
"{{cookiecutter.project_slug}}.cli.main")
return 0
{%- endif %}


if __name__ == "__main__":
sys.exit(main()) # pragma: no cover
{%- endif %}

0 comments on commit 755b6b5

Please sign in to comment.