From 420431d4b0ab1b5975bd18f38193bc53a99fafb6 Mon Sep 17 00:00:00 2001 From: Nick Petrovic <4001122+nickpetrovic@users.noreply.github.com> Date: Sun, 22 Dec 2024 21:23:00 -0500 Subject: [PATCH] reorder subcommands --- sdk/src/beta9/cli/extraclick.py | 15 ++++ sdk/src/beta9/cli/main.py | 2 +- sdk/src/beta9/cli/volume.py | 136 ++++++++++++++++---------------- 3 files changed, 84 insertions(+), 69 deletions(-) diff --git a/sdk/src/beta9/cli/extraclick.py b/sdk/src/beta9/cli/extraclick.py index 6b4e4bb36..18adea52f 100644 --- a/sdk/src/beta9/cli/extraclick.py +++ b/sdk/src/beta9/cli/extraclick.py @@ -83,10 +83,16 @@ def format_help_text(self, ctx: click.Context, formatter: click.HelpFormatter) - class ClickCommonGroup(click.Group): command_class = Beta9Command + def list_commands(self, ctx) -> List[str]: + return list(self.commands) + class ClickManagementGroup(click.Group): command_class = Beta9Command + def list_commands(self, ctx) -> List[str]: + return list(self.commands) + class CommandGroupCollection(click.CommandCollection): def __init__(self, *args, **kwargs): @@ -146,6 +152,9 @@ def format_commands(self, ctx: click.Context, formatter: click.HelpFormatter) -> else: commands["common"].append((subcommand, cmd)) + # sort the management commands + commands["management"].sort(key=lambda x: x[0]) + for cmdtype, cmds in commands.items(): if not len(cmds): continue @@ -161,6 +170,12 @@ def format_commands(self, ctx: click.Context, formatter: click.HelpFormatter) -> with formatter.section(gettext(cmdtype.title() + " Commands")): formatter.write_dl(rows) + def list_commands(self, ctx): + sources = [] + for source in self.sources: + sources.extend(source.list_commands(ctx)) + return sources + def pass_service_client(func: Callable): """ diff --git a/sdk/src/beta9/cli/main.py b/sdk/src/beta9/cli/main.py index 47630a1f6..c57e70412 100644 --- a/sdk/src/beta9/cli/main.py +++ b/sdk/src/beta9/cli/main.py @@ -93,9 +93,9 @@ def load_cli(check_config=True, **kwargs: Any) -> CLI: cli = CLI(**kwargs) cli.register(task) cli.register(deployment) + cli.register(serve) cli.register(volume) cli.register(config) - cli.register(serve) cli.register(pool) cli.register(container) cli.register(machine) diff --git a/sdk/src/beta9/cli/volume.py b/sdk/src/beta9/cli/volume.py index 00f7d27b0..e55d324b9 100644 --- a/sdk/src/beta9/cli/volume.py +++ b/sdk/src/beta9/cli/volume.py @@ -97,74 +97,6 @@ def ls(service: ServiceClient, remote_path: str): terminal.print(table) -@common.command( - help="Download contents from a volume.", -) -@click.argument( - "volume_name", - type=click.STRING, - required=True, -) -@click.argument( - "remote_path", - type=click.STRING, - required=True, -) -@click.argument( - "local_path", - type=click.Path(path_type=Path), - required=True, -) -@extraclick.pass_service_client -def download(service: ServiceClient, volume_name: str, remote_path: str, local_path: Path): - try: - with StyledProgress() as p: - task_id = p.add_task(local_path) - callback = cast(ProgressCallback, functools.partial(p.update, task_id=task_id)) - - multipart.download(service.volume, volume_name, remote_path, local_path, callback) - - except KeyboardInterrupt: - terminal.warn("\rDownload cancelled") - - except Exception as e: - terminal.error(f"\rDownload failed: {e}") - - -@common.command( - help="Upload contents from a volume.", -) -@click.argument( - "local_path", - type=click.Path(path_type=Path), - required=True, -) -@click.argument( - "volume_name", - type=click.STRING, - required=True, -) -@click.argument( - "remote_path", - type=click.STRING, - required=True, -) -@extraclick.pass_service_client -def upload(service: ServiceClient, local_path: Path, volume_name: str, remote_path: str): - try: - with StyledProgress() as p: - task_id = p.add_task(local_path) - callback = cast(ProgressCallback, functools.partial(p.update, task_id=task_id)) - - multipart.upload(service.volume, local_path, volume_name, remote_path, callback) - - except KeyboardInterrupt: - terminal.warn("\rUpload cancelled") - - except Exception as e: - terminal.error(f"\rUpload failed: {e}") - - @common.command( help="Copy contents to a volume.", epilog=""" @@ -341,6 +273,74 @@ def mv(service: ServiceClient, original_path: str, new_path: str): terminal.success(f"Moved {original_path} to {res.new_path}") +@common.command( + help="[Experimental] Upload contents from a volume.", +) +@click.argument( + "local_path", + type=click.Path(path_type=Path), + required=True, +) +@click.argument( + "volume_name", + type=click.STRING, + required=True, +) +@click.argument( + "remote_path", + type=click.STRING, + required=True, +) +@extraclick.pass_service_client +def upload(service: ServiceClient, local_path: Path, volume_name: str, remote_path: str): + try: + with StyledProgress() as p: + task_id = p.add_task(local_path) + callback = cast(ProgressCallback, functools.partial(p.update, task_id=task_id)) + + multipart.upload(service.volume, local_path, volume_name, remote_path, callback) + + except KeyboardInterrupt: + terminal.warn("\rUpload cancelled") + + except Exception as e: + terminal.error(f"\rUpload failed: {e}") + + +@common.command( + help="[Experimental] Download contents from a volume.", +) +@click.argument( + "volume_name", + type=click.STRING, + required=True, +) +@click.argument( + "remote_path", + type=click.STRING, + required=True, +) +@click.argument( + "local_path", + type=click.Path(path_type=Path), + required=True, +) +@extraclick.pass_service_client +def download(service: ServiceClient, volume_name: str, remote_path: str, local_path: Path): + try: + with StyledProgress() as p: + task_id = p.add_task(local_path) + callback = cast(ProgressCallback, functools.partial(p.update, task_id=task_id)) + + multipart.download(service.volume, volume_name, remote_path, local_path, callback) + + except KeyboardInterrupt: + terminal.warn("\rDownload cancelled") + + except Exception as e: + terminal.error(f"\rDownload failed: {e}") + + @click.group( name="volume", help="Manage volumes.",