From be9993ab2e7c191d17b5760d728646a2c4aed481 Mon Sep 17 00:00:00 2001 From: garciadeblas Date: Mon, 4 Aug 2025 12:58:46 +0200 Subject: [PATCH] Fix require_hostname function to consider nested commands such as cluster-get-kubeconfig Change-Id: I04e30b0cf7d7d94c7b9859758a564e687725b726 Signed-off-by: garciadeblas --- osmclient/cli_commands/cluster.py | 3 ++- osmclient/cli_commands/utils.py | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/osmclient/cli_commands/cluster.py b/osmclient/cli_commands/cluster.py index 83d5c65..31fe137 100755 --- a/osmclient/cli_commands/cluster.py +++ b/osmclient/cli_commands/cluster.py @@ -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") diff --git a/osmclient/cli_commands/utils.py b/osmclient/cli_commands/utils.py index 4ef7ad4..33bae82 100755 --- a/osmclient/cli_commands/utils.py +++ b/osmclient/cli_commands/utils.py @@ -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 -- 2.25.1