-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #731 from audreyfeldroy/add-typer-for-cli
Add typer for cli
- Loading branch information
Showing
4 changed files
with
15 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 13 additions & 27 deletions
40
{{cookiecutter.project_slug}}/src/{{cookiecutter.project_slug}}/cli.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,21 @@ | ||
"""Console script for {{cookiecutter.project_slug}}.""" | ||
import {{cookiecutter.project_slug}} | ||
|
||
{%- if cookiecutter.command_line_interface|lower == 'argparse' %} | ||
import argparse | ||
{%- endif %} | ||
import sys | ||
{%- if cookiecutter.command_line_interface|lower == 'click' %} | ||
import click | ||
{%- endif %} | ||
import typer | ||
from rich.console import Console | ||
|
||
{% 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' %} | ||
app = typer.Typer() | ||
console = Console() | ||
|
||
|
||
@app.command() | ||
def main(): | ||
"""Console script for {{cookiecutter.project_slug}}.""" | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('_', nargs='*') | ||
args = parser.parse_args() | ||
|
||
print("Arguments: " + str(args._)) | ||
print("Replace this message by putting your code into " | ||
"{{cookiecutter.project_slug}}.cli.main") | ||
return 0 | ||
{%- endif %} | ||
console.print("Replace this message by putting your code into " | ||
"{{cookiecutter.project_slug}}.cli.main") | ||
console.print("See Typer documentation at https://typer.tiangolo.com/") | ||
|
||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) # pragma: no cover | ||
app() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters