Created
October 5, 2021 12:09
-
-
Save opalczynski/49ecf024bf4b75d941dd33a3bd6bd45e to your computer and use it in GitHub Desktop.
cli_bare_bones - CLI example for blog post
This file contains hidden or 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
| import typer | |
| app = typer.Typer() | |
| project_app = typer.Typer() | |
| task_app = typer.Typer() | |
| project_app.add_typer(task_app, name="tasks") | |
| app.add_typer(project_app, name="projects") | |
| @project_app.command("list") | |
| def project_list(): | |
| """List of the available projects.""" | |
| typer.echo("List of projects") | |
| @project_app.command("create") | |
| def project_create(project_name: str, description: str = None): | |
| """Create the new project.""" | |
| typer.echo(f"Create new project: {project_name}, {description}") | |
| @task_app.command("list") | |
| def task_list(project_name: str): | |
| """List of the available tasks in given project.""" | |
| typer.echo(f"List all tasks in given project: {project_name}") | |
| @task_app.command("open") | |
| def task_open(task_id: int): | |
| """Open the task with task_id.""" | |
| typer.echo(f"Opening the task: {task_id}") | |
| @task_app.command("close") | |
| def task_close(task_id: int): | |
| """Close the task with task_id.""" | |
| typer.echo(f"Closing the task: {task_id}") | |
| @task_app.command("show") | |
| def task_close(task_id: int): | |
| """Show the task details with task_id.""" | |
| typer.echo(f"Task details: {task_id}") | |
| @task_app.command("create") | |
| def task_create(project_name: str, title: str, description: str = None): | |
| """Create new task.""" | |
| typer.echo(f"Creating the new task: {project_name}, {title}, {description}") | |
| if __name__ == "__main__": | |
| app() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment