Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions th_cli/commands/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
italic,
)
from th_cli.exceptions import CLIError, handle_api_error, handle_file_error
from th_cli.utils import __print_json, read_pics_config
from th_cli.utils import __print_config, __print_json, read_pics_config
from th_cli.validation import validate_directory_path

TABLE_FORMAT = "{:<5} {:25} {:28}"
Expand Down Expand Up @@ -125,20 +125,29 @@ def create(name: str, config: str | None, pics_config_folder: str | None) -> Non
)
@click.option(
"--json",
"-j",
is_flag=True,
default=False,
help=colorize_help("Print JSON response for more details"),
)
@click.option(
"--config",
"-c",
is_flag=True,
default=False,
help=colorize_help("Print project configuration in JSON format")
)
Comment thread
antonio-amjr marked this conversation as resolved.
def list_projects(
id: int | None,
skip: int | None,
limit: int | None,
archived: bool,
json: bool,
config: bool,
) -> None:
"""List projects"""
with get_sync_apis("list") as sync_apis:
_list_projects(sync_apis, id, archived, skip, limit, json)
_list_projects(sync_apis, id, archived, skip, limit, json, config)


# Click command to update an existing project
Expand Down Expand Up @@ -253,6 +262,7 @@ def _list_projects(
skip: int | None,
limit: int | None,
json: bool,
config: bool,
) -> None:
"""List projects"""

Expand Down Expand Up @@ -300,6 +310,8 @@ def __print_project(project: dict) -> None:

if json:
__print_json(projects)
elif config:
__print_config(projects)
else:
__print_table(projects)
Comment thread
rquidute marked this conversation as resolved.

Expand Down
5 changes: 5 additions & 0 deletions th_cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
def __print_json(object: Any) -> None:
click.echo(colorize_dump(__json_string(object)))

def __print_config(project: Any) -> None:
if isinstance(project, list):
raise CLIError("Please provide a single project ID (using --id) to print the configuration.")
config = project.config if project.config is not None else {}
click.echo(colorize_dump(json.dumps(config, indent=4, default=str)))

def __json_string(object: Any) -> str:
if object is None:
Expand Down