Skip to content

Commit

Permalink
fix: set click object to empty dict if DNE
Browse files Browse the repository at this point in the history
  • Loading branch information
fubuloubu authored Aug 2, 2024
1 parent 053ac15 commit cfb6f2e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions silverback/_click_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def auth_required(f):
@profile_option
@click.pass_context
def add_auth(ctx: click.Context, *args, **kwargs):
ctx.obj = ctx.obj or {}
profile: BaseProfile = ctx.obj["profile"]

if isinstance(profile, PlatformProfile):
Expand All @@ -144,6 +145,7 @@ def platform_client(f):
@auth_required
@click.pass_context
def get_platform_client(ctx: click.Context, *args, **kwargs):
ctx.obj = ctx.obj or {}
if not isinstance(profile := ctx.obj["profile"], PlatformProfile):
if not expose_value:
return ctx.invoke(f, *args, **kwargs)
Expand Down Expand Up @@ -173,6 +175,7 @@ def get_platform_client(ctx: click.Context, *args, **kwargs):
def cluster_client(f):

def inject_cluster(ctx, param, value: str | None):
ctx.obj = ctx.obj or {}
if isinstance(ctx.obj["profile"], ClusterProfile):
return value # Ignore processing this for cluster clients

Expand All @@ -197,6 +200,7 @@ def inject_cluster(ctx, param, value: str | None):
@platform_client
@click.pass_context
def get_cluster_client(ctx: click.Context, *args, **kwargs):
ctx.obj = ctx.obj or {}
if isinstance(profile := ctx.obj["profile"], ClusterProfile):
kwargs["cluster"] = ClusterClient(
base_url=profile.host,
Expand Down

0 comments on commit cfb6f2e

Please sign in to comment.