diff --git a/cli/trakcli/create/commands/session.py b/cli/trakcli/create/commands/session.py index 1828a40..87b3ae3 100644 --- a/cli/trakcli/create/commands/session.py +++ b/cli/trakcli/create/commands/session.py @@ -100,10 +100,18 @@ def create_session( help="Check the session you are about to create, without save it.", ), ] = False, + archived: Annotated[ + Optional[bool], + typer.Option( + "--archived", + "-a", + help="Show archived projects in lists.", + ), + ] = False, ): # # Project checking - projects_in_config = get_projects_from_config() + projects_in_config = get_projects_from_config(archived) # Check if there are configured projects if not len(projects_in_config): diff --git a/cli/trakcli/create/commands/work.py b/cli/trakcli/create/commands/work.py index 9d08459..1cb2658 100644 --- a/cli/trakcli/create/commands/work.py +++ b/cli/trakcli/create/commands/work.py @@ -1,5 +1,5 @@ from datetime import datetime -from typing import Annotated +from typing import Annotated, Optional import typer from rich import print as rprint @@ -76,8 +76,16 @@ def create_work( help="", ), ] = 1, + archived: Annotated[ + Optional[bool], + typer.Option( + "--archived", + "-a", + help="Show archived projects in lists.", + ), + ] = False, ): - projects_in_config = get_projects_from_config() + projects_in_config = get_projects_from_config(archived) if project_id in projects_in_config: details = get_project_from_config(project_id) diff --git a/cli/trakcli/projects/commands.py b/cli/trakcli/projects/commands.py index 1d4fca8..95961d9 100644 --- a/cli/trakcli/projects/commands.py +++ b/cli/trakcli/projects/commands.py @@ -1,5 +1,6 @@ import pathlib import shutil +from typing import Annotated, Optional import typer from rich import print as rprint @@ -8,11 +9,9 @@ from trakcli.config.main import ( TRAK_FOLDER, - get_db_file_path, ) from trakcli.projects.database import ( get_projects_from_config, - get_projects_from_db, ) from trakcli.utils.print_with_padding import print_with_padding @@ -20,14 +19,20 @@ @app.command(help="List your projects.") -def list(): +def list( + archived: Annotated[ + Optional[bool], + typer.Option( + "--archived", + "-a", + help="Show archived projects in lists.", + ), + ] = False, +): """List the projects.""" - db_path = get_db_file_path() - - projects_in_db = get_projects_from_db(db_path) - projects_in_config = get_projects_from_config() - combined = {*projects_in_db, *projects_in_config} + projects_in_config = get_projects_from_config(archived) + combined = {*projects_in_config} number_of_projects = len(combined) @@ -41,27 +46,8 @@ def list(): for project in projects_in_config: table.add_row(project, "config") - projects_id_db_only = False - for project in projects_in_db: - if project not in projects_in_config: - projects_id_db_only = True - table.add_row(project, "database") - rprint("") rprint(table) - rprint("") - if projects_id_db_only: - rprint( - Panel.fit( - title="Tip", - renderable=print_with_padding( - ( - "You have projects that don't exist in configuration.\n" - "Plase, run the `trak create project ` command to configure your project." - ) - ), - ) - ) @app.command(help="Delete a project.") diff --git a/cli/trakcli/projects/database.py b/cli/trakcli/projects/database.py index 8026f90..f910bbb 100644 --- a/cli/trakcli/projects/database.py +++ b/cli/trakcli/projects/database.py @@ -6,7 +6,7 @@ def get_projects_from_db(db_path: Path): - """Get the projects in the database.""" + """Deprecated. Get the projects in the database.""" with open(db_path, "r") as db: db_content = db.read() @@ -16,7 +16,7 @@ def get_projects_from_db(db_path: Path): return {record.get("project", "") for record in parsed_json} -def get_projects_from_config(): +def get_projects_from_config(archived: bool | None = False): """Get the projects in the config.""" projects_path = pathlib.Path(TRAK_FOLDER / "projects") @@ -28,7 +28,9 @@ def get_projects_from_config(): details_path = x / "details.json" with open(details_path, "r") as f: details = json.load(f) - projects.append(details.get("id", "ERROR: No id!")) + + if not details.get("archived") or archived: + projects.append(details.get("id", "ERROR: No id!")) return projects diff --git a/cli/trakcli/report/commands/report_project.py b/cli/trakcli/report/commands/report_project.py index dcfa54c..2586e93 100644 --- a/cli/trakcli/report/commands/report_project.py +++ b/cli/trakcli/report/commands/report_project.py @@ -103,15 +103,23 @@ def report_project( formats=["%Y-%m-%d"], ), ] = None, + archived: Annotated[ + Optional[bool], + typer.Option( + "--archived", + "-a", + help="Show archived projects in lists.", + ), + ] = False, ): """ Get reports for your projects. The projects will be get by the configuration in the .trak folder. """ - projects_in_config = get_projects_from_config() + projects_in_config = get_projects_from_config(archived) - projects_in_config.append("all") + projects_in_config.append(ALL_PROJECTS) # Check if there are configured projects if not len(projects_in_config): diff --git a/cli/trakcli/tracker/commands/start_tracker.py b/cli/trakcli/tracker/commands/start_tracker.py index bf2bba4..c50f126 100644 --- a/cli/trakcli/tracker/commands/start_tracker.py +++ b/cli/trakcli/tracker/commands/start_tracker.py @@ -44,12 +44,20 @@ def start_tracker( help="Add a tag to the tracked time. Useful in the reporting phase.", ), ] = "", + archived: Annotated[ + Optional[bool], + typer.Option( + "--archived", + "-a", + help="Show archived projects in lists.", + ), + ] = False, ): """ Start tracking a project by project_id. """ - projects_in_config = get_projects_from_config() + projects_in_config = get_projects_from_config(archived) if not project: project = questionary.select( diff --git a/cli/trakcli/works/commands/delete.py b/cli/trakcli/works/commands/delete.py index cbca720..4da20e4 100644 --- a/cli/trakcli/works/commands/delete.py +++ b/cli/trakcli/works/commands/delete.py @@ -1,13 +1,12 @@ -from typing import Annotated -from rich.panel import Panel -from trakcli.projects.utils.print_missing_project import print_missing_project -from rich.prompt import Confirm - +from typing import Annotated, Optional import typer from rich import print as rprint +from rich.panel import Panel +from rich.prompt import Confirm from trakcli.projects.database import get_projects_from_config +from trakcli.projects.utils.print_missing_project import print_missing_project from trakcli.works.database import ( get_project_works_from_config, set_project_works_in_config, @@ -22,10 +21,18 @@ def delete_work( "--in", "--of", "-p", help="The project's id in which the work is located." ), ], + archived: Annotated[ + Optional[bool], + typer.Option( + "--archived", + "-a", + help="Show archived projects in lists.", + ), + ] = False, ): """Delete a work from a project.""" - projects = get_projects_from_config() + projects = get_projects_from_config(archived) if project_id in projects: delete = Confirm.ask( diff --git a/cli/trakcli/works/commands/done.py b/cli/trakcli/works/commands/done.py index 18548d6..5821808 100644 --- a/cli/trakcli/works/commands/done.py +++ b/cli/trakcli/works/commands/done.py @@ -1,4 +1,4 @@ -from typing import Annotated +from typing import Annotated, Optional import typer from rich import print as rprint @@ -22,10 +22,18 @@ def done_work( "--in", "--of", "-p", help="The project's id in which the work is located." ), ], + archived: Annotated[ + Optional[bool], + typer.Option( + "--archived", + "-a", + help="Show archived projects in lists.", + ), + ] = False, ): """Mark as done a work of a project.""" - projects = get_projects_from_config() + projects = get_projects_from_config(archived) if project_id in projects: confirm_done = Confirm.ask( diff --git a/cli/trakcli/works/commands/list.py b/cli/trakcli/works/commands/list.py index 9d1c08a..64e083b 100644 --- a/cli/trakcli/works/commands/list.py +++ b/cli/trakcli/works/commands/list.py @@ -1,5 +1,5 @@ from datetime import datetime -from typing import Annotated +from typing import Annotated, Optional from rich.panel import Panel from trakcli.projects.utils.print_missing_project import print_with_padding @@ -87,6 +87,14 @@ def list_works( done: Annotated[ bool, typer.Option("--done", "-d", help="Show also done works.") ] = False, + archived: Annotated[ + Optional[bool], + typer.Option( + "--archived", + "-a", + help="Show archived projects in lists.", + ), + ] = False, ): """List the works in a project or all of them.""" @@ -105,7 +113,7 @@ def list_works( return else: # Show all current projects - projects = get_projects_from_config() + projects = get_projects_from_config(archived) for project in projects: works = get_project_works_from_config(project) diff --git a/cli/trakcli/works/commands/paid.py b/cli/trakcli/works/commands/paid.py index 2d498be..2d63de1 100644 --- a/cli/trakcli/works/commands/paid.py +++ b/cli/trakcli/works/commands/paid.py @@ -1,4 +1,4 @@ -from typing import Annotated +from typing import Annotated, Optional import typer from rich import print as rprint @@ -22,10 +22,18 @@ def paid_work( "--in", "--of", "-p", help="The project's id in which the work is located." ), ], + archived: Annotated[ + Optional[bool], + typer.Option( + "--archived", + "-a", + help="Show archived projects in lists.", + ), + ] = False, ): """Mark a work of a project as paid.""" - projects = get_projects_from_config() + projects = get_projects_from_config(archived) if project_id in projects: confirm_done = Confirm.ask(