-
Notifications
You must be signed in to change notification settings - Fork 2
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 #66 from lcfd/issue-62
[projects] Add trak projects archive <project-id> command #62
- Loading branch information
Showing
14 changed files
with
208 additions
and
53 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
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
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import typer | ||
|
||
from trakcli.projects.commands.archive import command_project_archive | ||
from trakcli.projects.commands.delete import command_project_delete | ||
from trakcli.projects.commands.list import command_project_list | ||
|
||
app = typer.Typer() | ||
|
||
|
||
app.command(name="list", help="List your projects.")(command_project_list) | ||
app.command(name="delete", help="Delete a project.")(command_project_delete) | ||
app.command(name="archive", help="Archive a project.")(command_project_archive) |
Empty file.
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import json | ||
from typing import Annotated, Optional | ||
|
||
import questionary | ||
import typer | ||
|
||
from trakcli.config.models import Project | ||
from trakcli.projects.database import ( | ||
db_get_project_details, | ||
db_get_project_details_path, | ||
get_projects_from_config, | ||
) | ||
from trakcli.projects.messages.print_project_archived_toggle import ( | ||
print_project_archived_toggle, | ||
) | ||
from trakcli.projects.messages.print_project_broken_configuration import ( | ||
print_project_broken_configuration, | ||
) | ||
from trakcli.projects.utils.print_missing_project import print_missing_project | ||
from trakcli.projects.utils.print_no_projects import print_no_projects | ||
from trakcli.utils.styles_questionary import questionary_style_select | ||
from rich import print as rprint | ||
|
||
|
||
def command_project_archive(project: Annotated[Optional[str], typer.Argument()] = None): | ||
"""Archive a project.""" | ||
|
||
projects_in_config = get_projects_from_config(True) | ||
|
||
# Check if there are configured projects | ||
if not len(projects_in_config): | ||
print_no_projects() | ||
return | ||
|
||
# Provide the list of prjects to the user | ||
if not project: | ||
project = questionary.select( | ||
"Select a project:", | ||
choices=projects_in_config, | ||
pointer="• ", | ||
show_selected=True, | ||
style=questionary_style_select, | ||
).ask() | ||
|
||
if not project: | ||
return | ||
|
||
# Check if the project exists | ||
if not project or project not in projects_in_config: | ||
print_missing_project(projects_in_config) | ||
return | ||
|
||
details_path = db_get_project_details_path(project) | ||
details = db_get_project_details(project) | ||
|
||
if details_path and details: | ||
# Toggle the value of archived | ||
details = details._replace(archived=not details.archived) | ||
|
||
with open(details_path, "w") as details_file: | ||
json.dump( | ||
details._asdict(), | ||
details_file, | ||
indent=2, | ||
separators=(",", ": "), | ||
) | ||
print_project_archived_toggle(project, details.archived) | ||
else: | ||
print_project_broken_configuration(project) | ||
return |
46 changes: 2 additions & 44 deletions
46
cli/trakcli/projects/commands.py → cli/trakcli/projects/commands/delete.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
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from typing import Annotated, Optional | ||
|
||
import typer | ||
from rich import print as rprint | ||
from rich.table import Table | ||
|
||
from trakcli.projects.database import get_projects_from_config | ||
|
||
|
||
def command_project_list( | ||
archived: Annotated[ | ||
Optional[bool], | ||
typer.Option( | ||
"--archived", | ||
"-a", | ||
help="Show archived projects in lists.", | ||
), | ||
] = False, | ||
): | ||
"""List the projects.""" | ||
|
||
projects_in_config = get_projects_from_config(archived) | ||
combined = {*projects_in_config} | ||
|
||
number_of_projects = len(combined) | ||
|
||
table = Table( | ||
title=f"{number_of_projects} Projects", | ||
) | ||
|
||
table.add_column("id", style="green", no_wrap=True) | ||
table.add_column("from", style="cyan", no_wrap=True) | ||
|
||
for project in projects_in_config: | ||
table.add_row(project, "config") | ||
|
||
rprint("") | ||
rprint(table) |
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
34 changes: 34 additions & 0 deletions
34
cli/trakcli/projects/messages/print_project_archived_toggle.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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from rich import print as rprint | ||
from rich.panel import Panel | ||
|
||
from trakcli.utils.print_with_padding import print_with_padding | ||
|
||
|
||
def print_project_archived_toggle(project_id: str, archived: bool): | ||
rprint("") | ||
if archived: | ||
rprint( | ||
Panel.fit( | ||
title=f"[green] The project {project_id} has been archived", | ||
renderable=print_with_padding( | ||
( | ||
"From now on this project won't be accessible from lists.\n\n" | ||
"[orange3]⭐Tip:[/orange3]\n" | ||
f"You can run trak [orange3]project archive {project_id}[/orange3] to unarchive it." | ||
) | ||
), | ||
) | ||
) | ||
else: | ||
rprint( | ||
Panel.fit( | ||
title=f"[green] The project {project_id} has been unarchived", | ||
renderable=print_with_padding( | ||
( | ||
"From now on this project will be accessible from lists.\n\n" | ||
"[orange3]⭐Tip:[/orange3]\n" | ||
f"You can run trak [orange3]project archive {project_id}[/orange3] to archive it." | ||
) | ||
), | ||
) | ||
) |
16 changes: 16 additions & 0 deletions
16
cli/trakcli/projects/messages/print_project_broken_configuration.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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from rich import print as rprint | ||
from rich.panel import Panel | ||
|
||
from trakcli.utils.print_with_padding import print_with_padding | ||
|
||
|
||
def print_project_broken_configuration(project_id: str): | ||
rprint("") | ||
rprint( | ||
Panel.fit( | ||
title=f"[red]The project {project_id} has broken configuration", | ||
renderable=print_with_padding( | ||
("Please, check the details.json file in your project folder.") | ||
), | ||
) | ||
) |
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