Skip to content

Commit

Permalink
feat: Enhance CLI with pretty printing options and improve usage docu…
Browse files Browse the repository at this point in the history
…mentation
  • Loading branch information
jjjermiah committed Dec 10, 2024
1 parent 6d85aab commit b186135
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
35 changes: 29 additions & 6 deletions src/orcestradownloader/cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import click
from click import Group, MultiCommand


from orcestradownloader.logging_config import set_log_verbosity
from orcestradownloader.managers import REGISTRY, DatasetManager, UnifiedDataManager
from orcestradownloader.models import ICBSet, PharmacoSet, RadioSet, ToxicoSet, XevaSet
Expand Down Expand Up @@ -75,11 +76,12 @@ def get_command(self, ctx, name):
@ds_group.command(name='list')
@set_log_verbosity()
@click.option('--force', is_flag=True, help='Force fetch new data')
@click.option('--no-pretty', is_flag=True, help='Disable pretty printing')
@click.pass_context
def _list(ctx, force: bool = False, verbose: int = 1, quiet: bool = False):
def _list(ctx, force: bool = False, no_pretty: bool = False, verbose: int = 1, quiet: bool = False):
"""List items for this dataset."""
manager = UnifiedDataManager(force=force)
manager.list_one(name)
manager.list_one(name, pretty=not no_pretty)

@ds_group.command(name='table')
@set_log_verbosity()
Expand All @@ -93,15 +95,36 @@ def _table(ctx, force: bool = False, verbose: int = 1, quiet: bool = False):
return ds_group
return None

def format_usage(self, ctx, formatter):
formatter.write_usage(
"orcestra",
"[DATASET_TYPE] [SUBCOMMAND] [ARGS]..."
)

@click.command(cls=DatasetMultiCommand, context_settings=CONTEXT_SETTINGS)
@click.help_option("-h", "--help", help="Show this message and exit.")
@click.pass_context
def cli(ctx, force: bool = False, verbose: int = 1, quiet: bool = False):
"""Manage all datasets dynamically.
"""
Interactive CLI for datasets on orcestra.ca
-------------------------------------------
\b
Subcommands:
- list
- table
Each dataset currently supports the following subcommands:
\b
list: List all items in the dataset
table: Print a table of items in the dataset
\b
Example:
\b
orcestra pharmacosets list
orcestra xevasets table --force
To get help on a subcommand, use:
orcestra [dataset_type] [subcommand] --help
"""
ctx.ensure_object(dict)
ctx.obj['force'] = force
Expand Down
14 changes: 10 additions & 4 deletions src/orcestradownloader/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,12 @@ def list_one(self, name: str, pretty: bool = True) -> None:
if pretty:
Console().print(f'[bold]{name}:[/]')
for ds_name in ds_names:
Console().print(f' - {ds_name}')
Console().print(f' - [green]{ds_name}[/]')
else:
Console().print(f'{name}: {ds_names}')
import click

for ds_name in ds_names:
click.echo(ds_name)

def list_all(self, pretty: bool = True) -> None:
"""List all datasets."""
Expand All @@ -231,7 +234,10 @@ def list_all(self, pretty: bool = True) -> None:
for name, ds_names in ds_dict.items():
Console().print(f'[bold]{name}:[/]')
for ds_name in ds_names:
Console().print(f' - {ds_name}')
Console().print(f' - [green]{ds_name}[/]')
else:
for name, ds_names in ds_dict.items():
Console().print(f'{name}: {ds_names}')
import click

for ds_name in ds_names:
click.echo(f'{name},{ds_name}')

0 comments on commit b186135

Please sign in to comment.