Fix require_hostname function to consider nested commands such as cluster-get-kubeconfig 12/15312/2
authorgarciadeblas <gerardo.garciadeblas@telefonica.com>
Mon, 4 Aug 2025 10:58:46 +0000 (12:58 +0200)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Mon, 4 Aug 2025 12:01:20 +0000 (14:01 +0200)
Change-Id: I04e30b0cf7d7d94c7b9859758a564e687725b726
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
osmclient/cli_commands/cluster.py
osmclient/cli_commands/utils.py

index 83d5c65..31fe137 100755 (executable)
@@ -280,7 +280,8 @@ def cluster_get_credentials(ctx, name, **kwargs):
 @click.pass_context
 def cluster_get_kubeconfig(ctx, name, **kwargs):
     """Alias for the cluster-get-credentials command"""
-    ctx.invoke(cluster_get_credentials, name=name)
+    logger.debug("")
+    ctx.forward(cluster_get_credentials)
 
 
 @click.command(name="cluster-register", short_help="registers a K8s cluster to OSM")
index 4ef7ad4..33bae82 100755 (executable)
@@ -113,9 +113,15 @@ def require_hostname(command):
         logger.debug("")
         hostname = ctx.parent.params.get("hostname") if ctx.parent else None
         if not hostname:
-            raise click.UsageError(
-                "This command requires --hostname or OSM_HOSTNAME to be set."
+            # Also check the parent of the parent in case of nested commands
+            # e.g., in 'osm cluster-get-kubeconfig'
+            hostname2 = (
+                ctx.parent.parent.params.get("hostname") if ctx.parent.parent else None
             )
+            if not hostname2:
+                raise click.UsageError(
+                    "This command requires --hostname or OSM_HOSTNAME to be set."
+                )
         return ctx.invoke(command, *args, **kwargs)
 
     return wrapper