Skip to content

Commit

Permalink
Merge pull request #1069 from sirosen/cleanup-resilient-parsing
Browse files Browse the repository at this point in the history
Refine usage of click.Context.resilient_parsing
  • Loading branch information
sirosen authored Jan 13, 2025
2 parents 93bab5c + f6f1c86 commit 675ef8b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
8 changes: 1 addition & 7 deletions src/globus_cli/commands/endpoint/set_subscription_id.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import typing as t
import uuid

import click
Expand All @@ -11,14 +10,9 @@


class SubscriptionIdType(click.ParamType):
def get_type_annotation(self, param: click.Parameter) -> type:
return t.cast(type, str)

def convert(
self, value: str, param: click.Parameter | None, ctx: click.Context | None
) -> t.Any:
if value is None or (ctx and ctx.resilient_parsing):
return None
) -> str:
if value.lower() == "null":
return "null"
try:
Expand Down
4 changes: 1 addition & 3 deletions src/globus_cli/commands/gcs/endpoint/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ def get_metavar(self, _: click.Parameter) -> t.Optional[str]:

def convert(
self, value: str, param: click.Parameter | None, ctx: click.Context | None
) -> str | ExplicitNullType | None:
if value is None or (ctx and ctx.resilient_parsing):
return None
) -> str | ExplicitNullType:
if value.lower() == "null":
return EXPLICIT_NULL
if value.lower() == "default":
Expand Down
2 changes: 2 additions & 0 deletions src/globus_cli/parsing/shell_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@

def print_completer_option(f: C) -> C:
def callback(ctx: click.Context, param: click.Parameter, value: str | None) -> None:
# if `resilient_parsing=True`, shell completion is being executed, so we should
# be careful to skip the callback contents, which would echo output and exit
if not value or ctx.resilient_parsing:
return

Expand Down

0 comments on commit 675ef8b

Please sign in to comment.