From 7d319f585b31444ac097683bb340838856d0403a Mon Sep 17 00:00:00 2001 From: lcfd <9001053+fedriz@users.noreply.github.com> Date: Mon, 11 Dec 2023 00:30:59 +0100 Subject: [PATCH] Allow to start only projects in configuration --- cli/trakcli/main.py | 49 ++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/cli/trakcli/main.py b/cli/trakcli/main.py index c4a6f4c..bc0e519 100644 --- a/cli/trakcli/main.py +++ b/cli/trakcli/main.py @@ -26,6 +26,7 @@ from trakcli.dev.commands import app as dev_app from trakcli.initialize import initialize_trak from trakcli.projects.commands import app as projects_app +from trakcli.projects.database import get_projects_from_config from trakcli.report.commands.main import report from trakcli.utils.print_with_padding import print_with_padding from trakcli.create import app as create_app @@ -133,27 +134,43 @@ def start_tracker( project = typer.prompt("Which project do you want to track?") record = tracking_already_started() + projects_in_config = get_projects_from_config() if not record: - add_session( - Record( - project=project, - start=datetime.now().isoformat(), - billable=billable, - category=category, - tag=tag, + if project in projects_in_config: + add_session( + Record( + project=project, + start=datetime.now().isoformat(), + billable=billable, + category=category, + tag=tag, + ) ) - ) - rprint( - Panel.fit( - title="▶️ Start", - renderable=print_with_padding( - f"""[bold green]{project}[/bold green] started. + rprint( + Panel.fit( + title="▶️ Start", + renderable=print_with_padding( + f"""[bold green]{project}[/bold green] started. -Have a good session!""" - ), + Have a good session!""" + ), + ) ) - ) + else: + renderable_projects_list = "\n • ".join(projects_in_config) + rprint("") + rprint( + Panel( + title="[red]Missing project[/red]", + renderable=print_with_padding( + "This project doesn't exists.\n\n" + f"Awailable projects: \n • {renderable_projects_list}\n\n\n\n" + "Try to run the `trak create project ` command if you want to create a new project." + ), + ) + ) + return else: formatted_start_time = datetime.fromisoformat(record["start"]).strftime( "%m/%d/%Y, %H:%M"