From: garciadeblas Date: Mon, 4 Aug 2025 10:58:46 +0000 (+0200) Subject: Fix require_hostname function to consider nested commands such as cluster-get-kubeconfig X-Git-Tag: v18.0.0~2 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F12%2F15312%2F2;p=osm%2Fosmclient.git Fix require_hostname function to consider nested commands such as cluster-get-kubeconfig Change-Id: I04e30b0cf7d7d94c7b9859758a564e687725b726 Signed-off-by: garciadeblas --- 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