Skip to content

Commit e23ecc8

Browse files
authored
Add typer as cli option (#19)
1 parent 30edda9 commit e23ecc8

4 files changed

Lines changed: 21 additions & 0 deletions

File tree

cookiecutter.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"command_line_interface": [
1717
"argparse",
1818
"click",
19+
"typer",
1920
"none"
2021
],
2122
"build_docs": "y",

{{cookiecutter.repository_name}}/pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ readme = "README.md"
1212
dependencies = [
1313
'click'
1414
]
15+
{% elif cookiecutter.command_line_interface|lower == "typer" -%}
16+
dependencies = [
17+
'typer'
18+
]
1519
{%- endif %}
1620

1721
{% if cookiecutter.command_line_interface|lower != "y" -%}

{{cookiecutter.repository_name}}/src/{{cookiecutter.module_name}}/__main__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
from {{cookiecutter.module_name}}.cli import main
44
{% if cookiecutter.command_line_interface|lower != 'none' -%}
55
if __name__ == "__main__":
6+
{% if cookiecutter.command_line_interface|lower == 'typer' -%}
7+
import typer
8+
typer.run(main)
9+
{% else -%}
610
import sys
711
sys.exit(main())
12+
{% endif -%}
813
{% endif -%}

{{cookiecutter.repository_name}}/src/{{cookiecutter.module_name}}/cli.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{%- if cookiecutter.command_line_interface|lower == 'argparse' %}
33
import argparse
44

5+
56
def main():
67
"""Console script for {{cookiecutter.module_name}}."""
78
parser = argparse.ArgumentParser(
@@ -25,4 +26,14 @@ def main(count, name):
2526
for x in range(count):
2627
click.echo(f"Hello {name}!")
2728
return 0
29+
{%- elif cookiecutter.command_line_interface|lower == 'typer' %}
30+
import typer
31+
32+
33+
def main(count: int, name: str) -> int:
34+
"""Simple program that greets NAME for a total of COUNT times."""
35+
for x in range(count):
36+
typer.echo(f"Hello {name}!")
37+
return 0
38+
2839
{% endif -%}

0 commit comments

Comments
 (0)