diff --git a/src/workato_platform/cli/__init__.py b/src/workato_platform/cli/__init__.py index 9da456c..2345b80 100644 --- a/src/workato_platform/cli/__init__.py +++ b/src/workato_platform/cli/__init__.py @@ -1,5 +1,7 @@ """CLI tool for the Workato API""" +import typing as t + import asyncclick as click from workato_platform.cli.commands import ( @@ -23,7 +25,43 @@ from workato_platform.cli.utils.version_checker import check_updates_async -@click.group() +class AliasedGroup(click.Group): + """A Click Group that supports command aliases without showing them in help""" + + def __init__(self, *args: t.Any, **kwargs: t.Any) -> None: + super().__init__(*args, **kwargs) + self.aliases: dict[str, str] = {} + + def add_command_with_alias( + self, + cmd: click.Command, + name: str | None = None, + alias: str | None = None, + ) -> None: + """Add a command with an optional hidden alias""" + # Add the main command + self.add_command(cmd, name=name) + + # Store alias mapping + if alias: + main_name = name or cmd.name + if not main_name: + raise ValueError("Command must have a name to create an alias") + if alias == main_name: + raise ValueError( + f"Alias '{alias}' cannot be the same as " + f"the main command name '{main_name}'." + ) + self.aliases[alias] = main_name + + def get_command(self, ctx: click.Context, cmd_name: str) -> click.Command | None: + # Check if it's an alias first + if cmd_name in self.aliases: + cmd_name = self.aliases[cmd_name] + return super().get_command(ctx, cmd_name) + + +@click.group(cls=AliasedGroup) @click.option( "--profile", help="Profile to use for authentication and region settings", @@ -66,12 +104,9 @@ def cli( # Core setup and configuration commands cli.add_command(init.init) -cli.add_command(projects.projects) -cli.add_command(projects.projects, name="project") +cli.add_command_with_alias(projects.projects, alias="project") cli.add_command(profiles.profiles) -cli.add_command(profiles.profiles, name="profiles") -cli.add_command(properties.properties) -cli.add_command(properties.properties, name="property") +cli.add_command_with_alias(properties.properties, alias="property") # Development commands cli.add_command(guide.guide) @@ -79,20 +114,13 @@ def cli( cli.add_command(pull.pull) # API and resource management commands -cli.add_command(api_collections.api_collections) -cli.add_command(api_collections.api_collections, name="api-collection") -cli.add_command(api_clients.api_clients) -cli.add_command(api_clients.api_clients, name="api-client") -cli.add_command(data_tables.data_tables) -cli.add_command(data_tables.data_tables, name="data-table") -cli.add_command(connections.connections) -cli.add_command(connections.connections, name="connection") -cli.add_command(connectors.connectors) -cli.add_command(connectors.connectors, name="connector") -cli.add_command(recipes.recipes) -cli.add_command(recipes.recipes, name="recipe") +cli.add_command_with_alias(api_collections.api_collections, alias="api-collection") +cli.add_command_with_alias(api_clients.api_clients, alias="api-client") +cli.add_command_with_alias(data_tables.data_tables, alias="data-table") +cli.add_command_with_alias(connections.connections, alias="connection") +cli.add_command_with_alias(connectors.connectors, alias="connector") +cli.add_command_with_alias(recipes.recipes, alias="recipe") # Information commands -cli.add_command(assets.assets) -cli.add_command(assets.assets, name="asset") +cli.add_command_with_alias(assets.assets, alias="asset") cli.add_command(workspace.workspace)