From ff5532d9c9fde842f064664ca5829fffa83c46c7 Mon Sep 17 00:00:00 2001 From: Ossama Alami Date: Tue, 21 Oct 2025 11:09:57 -0700 Subject: [PATCH 1/7] Fix command listing to show only main commands, hiding singular aliases - Created a custom AliasedGroup class in /Users/ossama/dev/workato-platform-cli/src/workato_platform/cli/__init__.py:26-47 - Added add_command_with_alias() method that registers the command and stores alias mappings internally - Modified get_command() to resolve aliases to their main command names - Updated all command registrations to use add_command_with_alias() with the singular form as the hidden alias --- src/workato_platform/cli/__init__.py | 54 +++++++++++++++++----------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/src/workato_platform/cli/__init__.py b/src/workato_platform/cli/__init__.py index 9da456c..e847571 100644 --- a/src/workato_platform/cli/__init__.py +++ b/src/workato_platform/cli/__init__.py @@ -23,7 +23,31 @@ 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, **kwargs): + super().__init__(*args, **kwargs) + self.aliases = {} + + def add_command_with_alias(self, cmd, name=None, alias=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 + self.aliases[alias] = main_name + + def get_command(self, ctx, cmd_name): + # 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 +90,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 +100,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) From 3a5177a32bd6d5ae2a4de9b3cc969ab2c9b2b88c Mon Sep 17 00:00:00 2001 From: Ossama Alami Date: Tue, 21 Oct 2025 11:14:40 -0700 Subject: [PATCH 2/7] Update src/workato_platform/cli/__init__.py check that alias is not equal to the main command name Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/workato_platform/cli/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/workato_platform/cli/__init__.py b/src/workato_platform/cli/__init__.py index e847571..5aca111 100644 --- a/src/workato_platform/cli/__init__.py +++ b/src/workato_platform/cli/__init__.py @@ -38,6 +38,8 @@ def add_command_with_alias(self, cmd, name=None, alias=None): # Store alias mapping if alias: main_name = name or cmd.name + if alias == main_name: + raise ValueError(f"Alias '{alias}' cannot be the same as the main command name '{main_name}'.") self.aliases[alias] = main_name def get_command(self, ctx, cmd_name): From d7a2bb2e38b39ea70a14ac3dfaf8a5191828ca43 Mon Sep 17 00:00:00 2001 From: Ossama Alami Date: Tue, 21 Oct 2025 11:18:26 -0700 Subject: [PATCH 3/7] fix line length for linter --- src/workato_platform/cli/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/workato_platform/cli/__init__.py b/src/workato_platform/cli/__init__.py index 5aca111..c9ee768 100644 --- a/src/workato_platform/cli/__init__.py +++ b/src/workato_platform/cli/__init__.py @@ -39,7 +39,9 @@ def add_command_with_alias(self, cmd, name=None, alias=None): if alias: main_name = name or cmd.name if alias == main_name: - raise ValueError(f"Alias '{alias}' cannot be the same as the main command name '{main_name}'.") + raise ValueError( + f"Alias '{alias}' cannot be the same as the main command name '{main_name}'." + ) self.aliases[alias] = main_name def get_command(self, ctx, cmd_name): From c85e9a0497ff8d9279817ce674d794b3ae634016 Mon Sep 17 00:00:00 2001 From: Ossama Alami Date: Tue, 21 Oct 2025 11:29:07 -0700 Subject: [PATCH 4/7] fix errant checkin --- src/workato_platform/cli/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/workato_platform/cli/__init__.py b/src/workato_platform/cli/__init__.py index c9ee768..2ddbc5e 100644 --- a/src/workato_platform/cli/__init__.py +++ b/src/workato_platform/cli/__init__.py @@ -40,7 +40,8 @@ def add_command_with_alias(self, cmd, name=None, alias=None): main_name = name or cmd.name if alias == main_name: raise ValueError( - f"Alias '{alias}' cannot be the same as the main command name '{main_name}'." + f"Alias '{alias}' cannot be the same as " + f"the main command name '{main_name}'." ) self.aliases[alias] = main_name From 03ae44ad5bb63c5c6e96410cf262cbd97897115c Mon Sep 17 00:00:00 2001 From: Ossama Alami Date: Tue, 21 Oct 2025 11:37:08 -0700 Subject: [PATCH 5/7] fix linter errors --- src/workato_platform/cli/__init__.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/workato_platform/cli/__init__.py b/src/workato_platform/cli/__init__.py index 2ddbc5e..d9b0a4d 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 ( @@ -26,11 +28,16 @@ class AliasedGroup(click.Group): """A Click Group that supports command aliases without showing them in help""" - def __init__(self, *args, **kwargs): + def __init__(self, *args: t.Any, **kwargs: t.Any) -> None: super().__init__(*args, **kwargs) - self.aliases = {} - - def add_command_with_alias(self, cmd, name=None, alias=None): + 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) @@ -45,7 +52,7 @@ def add_command_with_alias(self, cmd, name=None, alias=None): ) self.aliases[alias] = main_name - def get_command(self, ctx, cmd_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] From 5a751743a3b9c0a957844bccd99710a3dd1f4201 Mon Sep 17 00:00:00 2001 From: Ossama Alami Date: Tue, 21 Oct 2025 11:45:42 -0700 Subject: [PATCH 6/7] fix linter --- src/workato_platform/cli/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/workato_platform/cli/__init__.py b/src/workato_platform/cli/__init__.py index d9b0a4d..54638f6 100644 --- a/src/workato_platform/cli/__init__.py +++ b/src/workato_platform/cli/__init__.py @@ -55,7 +55,9 @@ def add_command_with_alias( 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] + aliased_name = self.aliases[cmd_name] + if aliased_name is not None: + cmd_name = aliased_name return super().get_command(ctx, cmd_name) From 008b9f2be210a78acbc742d0ff0420c08f24629f Mon Sep 17 00:00:00 2001 From: Ossama Alami Date: Tue, 21 Oct 2025 11:49:50 -0700 Subject: [PATCH 7/7] fix linter error --- src/workato_platform/cli/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/workato_platform/cli/__init__.py b/src/workato_platform/cli/__init__.py index 54638f6..2345b80 100644 --- a/src/workato_platform/cli/__init__.py +++ b/src/workato_platform/cli/__init__.py @@ -45,6 +45,8 @@ def add_command_with_alias( # 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 " @@ -55,9 +57,7 @@ def add_command_with_alias( 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: - aliased_name = self.aliases[cmd_name] - if aliased_name is not None: - cmd_name = aliased_name + cmd_name = self.aliases[cmd_name] return super().get_command(ctx, cmd_name)