Skip to content

Commit d6bb158

Browse files
committed
add: plural alias to list raycluster
1 parent a2168b5 commit d6bb158

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/codeflare_sdk/cli/cli_utils.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,19 @@ def load_auth():
5757
click.echo("No authentication found, trying default kubeconfig")
5858
except client.ApiException:
5959
click.echo("Invalid authentication, trying default kubeconfig")
60+
61+
62+
class PluralAlias(click.Group):
63+
def get_command(self, ctx, cmd_name):
64+
rv = click.Group.get_command(self, ctx, cmd_name)
65+
if rv is not None:
66+
return rv
67+
for x in self.list_commands(ctx):
68+
if x + "s" == cmd_name:
69+
return click.Group.get_command(self, ctx, x)
70+
return None
71+
72+
def resolve_command(self, ctx, args):
73+
# always return the full command name
74+
_, cmd, args = super().resolve_command(ctx, args)
75+
return cmd.name, cmd, args

src/codeflare_sdk/cli/commands/list.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
from codeflare_sdk.cluster.cluster import (
55
list_clusters_all_namespaces,
66
list_all_clusters,
7-
get_current_namespace,
87
)
9-
from codeflare_sdk.cli.cli_utils import load_auth
8+
from codeflare_sdk.cli.cli_utils import PluralAlias
109

1110

12-
@click.group()
11+
@click.group(cls=PluralAlias)
1312
def cli():
1413
"""List a specified resource"""
1514
pass
@@ -19,7 +18,7 @@ def cli():
1918
@click.option("--namespace", type=str)
2019
@click.option("--all", is_flag=True)
2120
@click.pass_context
22-
def rayclusters(ctx, namespace, all):
21+
def raycluster(ctx, namespace, all):
2322
"""List all rayclusters in a specified namespace"""
2423
if all and namespace:
2524
click.echo("--all and --namespace are mutually exclusive")

0 commit comments

Comments
 (0)