Skip to content

Commit

Permalink
Add works done command
Browse files Browse the repository at this point in the history
  • Loading branch information
lcfd committed Dec 13, 2023
1 parent 9b3fc64 commit 039e673
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cli/trakcli/works/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import typer

from trakcli.works.commands.delete import delete_work
from trakcli.works.commands.done import done_work
from trakcli.works.commands.list import list_works

app = typer.Typer()


app.command("list")(list_works)
app.command("delete")(delete_work)
app.command("done")(done_work)
2 changes: 1 addition & 1 deletion cli/trakcli/works/commands/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def delete_work(
project_id: Annotated[
str,
typer.Option(
"--from", "-f", "-p", help="The project's id in which the work is located."
"--in", "--of", "-p", help="The project's id in which the work is located."
),
],
):
Expand Down
73 changes: 73 additions & 0 deletions cli/trakcli/works/commands/done.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from typing import Annotated

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.utils.print_with_padding import print_with_padding
from trakcli.works.database import (
get_project_works_from_config,
set_project_works_in_config,
)


def done_work(
work_id: Annotated[str, typer.Argument()],
project_id: Annotated[
str,
typer.Option(
"--in", "--of", "-p", help="The project's id in which the work is located."
),
],
):
"""Mark as done a work of a project."""

projects = get_projects_from_config()

if project_id in projects:
confirm_done = Confirm.ask(
f"Are you sure you want to mark the [green]{work_id}[/green] work from [green]{project_id}[/green] project as done?",
default=False,
)
if not confirm_done:
rprint("")
rprint("[yellow]Not marked as done.[/yellow]")
raise typer.Abort()

works = get_project_works_from_config(project_id)
if works is not None:
works_ids = [w["id"] for w in works]
if work_id in works_ids:
filtered_works = [
{**w, "done": True} if w["id"] == work_id else w for w in works
]

set_project_works_in_config(project_id, filtered_works)

rprint("")
rprint(
Panel.fit(
title="[green]Success[/green]",
renderable=f"Work {work_id} successfully from {project_id} project marked as done.",
)
)
else:
rprint("")
rprint(
Panel.fit(
title="[red]The work doesn't exist[/red]",
renderable=print_with_padding(
(
"You can create a new work with the command:\n"
"trak create work <work_id> -p <project_id> -n <name> -t <hours> --from 2024-01-01 --to 2024-02-01"
)
),
)
)

return
else:
print_missing_project(projects)

0 comments on commit 039e673

Please sign in to comment.