Skip to content

Commit

Permalink
reorder subcommands
Browse files Browse the repository at this point in the history
  • Loading branch information
nickpetrovic committed Dec 23, 2024
1 parent 1f9969e commit 420431d
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 69 deletions.
15 changes: 15 additions & 0 deletions sdk/src/beta9/cli/extraclick.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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):
"""
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/beta9/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
136 changes: 68 additions & 68 deletions sdk/src/beta9/cli/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="""
Expand Down Expand Up @@ -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.",
Expand Down

0 comments on commit 420431d

Please sign in to comment.