Option
A CLI Option is a parameter to your command line application that is called with a single or double dash, something like --verbose or -v.
def Option(
default: Any | None = ...,
param_decls: str,
callback: Callable[..., Any] | None = None,
metavar: str | None = None,
expose_value: bool = True,
is_eager: bool = False,
envvar: str | list[str] | None = None,
shell_complete: Callable | None = None,
autocompletion: Callable[..., Any] | None = None,
default_factory: Callable[[], Any] | None = None,
parser: Callable[[str], Any] | None = None,
click_type: click.ParamType | None = None,
show_default: bool | str = True,
prompt: bool | str = False,
confirmation_prompt: bool = False,
prompt_required: bool = True,
hide_input: bool = False,
is_flag: bool | None = None,
flag_value: Any | None = None,
count: bool = False,
allow_from_autoenv: bool = True,
help: str | None = None,
hidden: bool = False,
show_choices: bool = True,
show_envvar: bool = True,
case_sensitive: bool = True,
min: int | float | None = None,
max: int | float | None = None,
clamp: bool = False,
formats: list[str] | None = None,
mode: str | None = None,
encoding: str | None = None,
errors: str | None = "strict",
lazy: bool | None = None,
atomic: bool = False,
exists: bool = False,
file_okay: bool = True,
dir_okay: bool = True,
writable: bool = False,
readable: bool = True,
resolve_path: bool = False,
allow_dash: bool = False,
path_type: None | type[str] | type[bytes] = None,
rich_help_panel: str | None = None
) - > OptionInfo
A CLI Option is a parameter to your command line application that is called with a single or double dash, something like --verbose or -v.
Parameters
| Name | Type | Description |
|---|---|---|
| default | `Any | None` = ... |
| param_decls | str | One or multiple aliases (e.g., '--user', '-u') defining how the option is called on the command line. |
| callback | `Callable[..., Any] | None` = None |
| metavar | `str | None` = None |
| expose_value | bool = True | Whether to pass the value to the command callback and store it on the context. |
| is_eager | bool = False | If True, processes this option before other parameters to handle early-exit logic like version flags. |
| envvar | `str | list[str] |
| shell_complete | `Callable | None` = None |
| autocompletion | `Callable[..., Any] | None` = None |
| default_factory | `Callable[[], Any] | None` = None |
| parser | `Callable[[str], Any] | None` = None |
| click_type | `click.ParamType | None` = None |
| show_default | `bool | str` = True |
| prompt | `bool | str` = False |
| confirmation_prompt | bool = False | Whether to ask the user to type the value twice for confirmation (e.g., for passwords). |
| prompt_required | bool = True | If False, only prompts if the option flag is provided without an accompanying value. |
| hide_input | bool = False | Whether to mask user input during a prompt, typically used for sensitive data. |
| is_flag | `bool | None` = None |
| flag_value | `Any | None` = None |
| count | bool = False | Whether to treat the option as a counter that increments with each occurrence (e.g., -vvv). |
| allow_from_autoenv | bool = True | Whether to allow pulling values from environment variables based on a context prefix. |
| help | `str | None` = None |
| hidden | bool = False | Whether to hide this option from the help output entirely. |
| show_choices | bool = True | Whether to display valid Enum choices inline during an interactive prompt. |
| show_envvar | bool = True | Whether to display the associated environment variable name in the help text. |
| case_sensitive | bool = True | Whether Enum choice matching should respect character casing. |
| min | `int | float |
| max | `int | float |
| clamp | bool = False | Whether to force out-of-bounds numeric input to the nearest min/max boundary instead of erroring. |
| formats | `list[str] | None` = None |
| mode | `str | None` = None |
| encoding | `str | None` = None |
| errors | `str | None` = "strict" |
| lazy | `bool | None` = None |
| atomic | bool = False | Whether to perform file writes using a temporary file to ensure atomic updates. |
| exists | bool = False | Whether to validate that the provided Path exists on the filesystem. |
| file_okay | bool = True | Whether the Path is allowed to be a file. |
| dir_okay | bool = True | Whether the Path is allowed to be a directory. |
| writable | bool = False | Whether to check if the Path is writable by the current user. |
| readable | bool = True | Whether to check if the Path is readable by the current user. |
| resolve_path | bool = False | Whether to convert the Path to an absolute path and resolve all symlinks. |
| allow_dash | bool = False | Whether to allow '-' as a path value to represent stdin/stdout. |
| path_type | `None | type[str] |
| rich_help_panel | `str | None` = None |
Returns
| Type | Description |
|---|---|
OptionInfo | An object containing the configuration metadata for a Typer CLI option. |