diff --git a/typer/core.py b/typer/core.py index b197382029..20c860ab50 100644 --- a/typer/core.py +++ b/typer/core.py @@ -403,6 +403,9 @@ def make_metavar(self, ctx: Union[click.Context, None] = None) -> str: var += "..." return var + def value_is_missing(self, value: Any) -> bool: + return _value_is_missing(self, value) + class TyperOption(click.core.Option): def __init__( @@ -593,6 +596,23 @@ def _write_opts(opts: Sequence[str]) -> str: return ("; " if any_prefix_is_slash else " / ").join(rv), help + def value_is_missing(self, value: Any) -> bool: + return _value_is_missing(self, value) + + +def _value_is_missing(param: click.Parameter, value: Any) -> bool: + if value is None: + return True + + # Click 8.3 and beyond + # if value is UNSET: + # return True + + if (param.nargs != 1 or param.multiple) and value == (): + return True # pragma: no cover + + return False + def _typer_format_options( self: click.core.Command, *, ctx: click.Context, formatter: click.HelpFormatter