class documentation

class Option(Parameter):

View In Hierarchy

Options are usually optional values on the command line and have some extra features that arguments don't have.

All other parameters are passed onwards to the parameter constructor.

Changed in version 8.0.1: type is detected from flag_value if given.
Parameters
show​_defaultcontrols if the default value should be shown on the help page. Normally, defaults are not shown. If this value is a string, it shows the string instead of the value. This is particularly useful for dynamic options.
show​_envvarcontrols if an environment variable should be shown on the help page. Normally, environment variables are not shown.
promptif set to True or a non empty string then the user will be prompted for input. If set to True the prompt will be the option name capitalized.
confirmation​_promptPrompt a second time to confirm the value if it was prompted for. Can be set to a string instead of True to customize the message.
prompt​_requiredIf set to False, the user will be prompted for input only when the option was specified as a flag without a value.
hide​_inputif this is True then the input on the prompt will be hidden from the user. This is useful for password input.
is​_flagforces this option to act as a flag. The default is auto detection.
flag​_valuewhich value should be used for this flag if it's enabled. This is set to a boolean automatically if the option string contains a slash to mark two options.
multipleif this is set to True then the argument is accepted multiple times and recorded. This is similar to nargs in how it works but supports arbitrary number of arguments.
countthis flag makes an option increment an integer.
allow​_from​_autoenvif this is enabled then the value of this parameter will be pulled from an environment variable in case a prefix is defined on the context.
helpthe help string.
hiddenhide this option from help outputs.
Method __init__ Undocumented
Method ​_parse​_decls Undocumented
Method add​_to​_parser Undocumented
Method consume​_value Undocumented
Method get​_default Get the default for the parameter. Tries Context.lookup_default first, then the local default.
Method get​_help​_record Undocumented
Method prompt​_for​_value No summary
Method resolve​_envvar​_value Undocumented
Method to​_info​_dict Gather information that could be useful for a tool generating user-facing documentation.
Method value​_from​_envvar Undocumented
Class Variable param​_type​_name Undocumented
Instance Variable ​_flag​_needs​_value Undocumented
Instance Variable allow​_from​_autoenv Undocumented
Instance Variable confirmation​_prompt Undocumented
Instance Variable count Undocumented
Instance Variable default Undocumented
Instance Variable flag​_value Undocumented
Instance Variable help Undocumented
Instance Variable hidden Undocumented
Instance Variable hide​_input Undocumented
Instance Variable is​_bool​_flag Undocumented
Instance Variable is​_flag Undocumented
Instance Variable prompt Undocumented
Instance Variable prompt​_required Undocumented
Instance Variable show​_choices Undocumented
Instance Variable show​_default Undocumented
Instance Variable show​_envvar Undocumented
Instance Variable type Undocumented

Inherited from Parameter:

Method __repr__ Undocumented
Method get​_error​_hint Get a stringified version of the param for use in error messages to indicate which param caused the error.
Method get​_usage​_pieces Undocumented
Method handle​_parse​_result Undocumented
Method make​_metavar Undocumented
Method process​_value Undocumented
Method shell​_complete No summary
Method type​_cast​_value Convert and validate a value against the option's type, multiple, and nargs.
Method value​_is​_missing Undocumented
Instance Variable ​_custom​_shell​_complete Undocumented
Instance Variable callback Undocumented
Instance Variable envvar Undocumented
Instance Variable expose​_value Undocumented
Instance Variable is​_eager Undocumented
Instance Variable metavar Undocumented
Instance Variable multiple Undocumented
Instance Variable name Undocumented
Instance Variable nargs Undocumented
Instance Variable opts Undocumented
Instance Variable required Undocumented
Instance Variable secondary​_opts Undocumented
Property human​_readable​_name Returns the human readable name of this parameter. This is the same as the name for options, but the metavar for arguments.
def __init__(self, param_decls=None, show_default=False, prompt=False, confirmation_prompt=False, prompt_required=True, hide_input=False, is_flag=None, flag_value=None, multiple=False, count=False, allow_from_autoenv=True, type=None, help=None, hidden=False, show_choices=True, show_envvar=False, **attrs):

Undocumented

Parameters
param​_decls:t.Optional[t.Sequence[str]]Undocumented
show​_default:t.Union[bool, str]Undocumented
prompt:t.Union[bool, str]Undocumented
confirmation​_prompt:t.Union[bool, str]Undocumented
prompt​_required:boolUndocumented
hide​_input:boolUndocumented
is​_flag:t.Optional[bool]Undocumented
flag​_value:t.Optional[t.Any]Undocumented
multiple:boolUndocumented
count:boolUndocumented
allow​_from​_autoenv:boolUndocumented
type:t.Optional[t.Union[types.ParamType, t.Any]]Undocumented
help:t.Optional[str]Undocumented
hidden:boolUndocumented
show​_choices:boolUndocumented
show​_envvar:boolUndocumented
**attrs:t.AnyUndocumented
def _parse_decls(self, decls, expose_value):

Undocumented

Parameters
decls:t.Sequence[str]Undocumented
expose​_value:boolUndocumented
Returns
t.Tuple[t.Optional[str], t.List[str], t.List[str]]Undocumented
def add_to_parser(self, parser, ctx):

Undocumented

Parameters
parser:OptionParserUndocumented
ctx:ContextUndocumented
def consume_value(self, ctx, opts):

Undocumented

Parameters
ctx:ContextUndocumented
opts:t.Mapping[str, Parameter]Undocumented
Returns
t.Tuple[t.Any, ParameterSource]Undocumented
def get_default(self, ctx, call=True):

Get the default for the parameter. Tries Context.lookup_default first, then the local default.

Changed in version 8.0.2: Type casting is no longer performed when getting a default.
Changed in version 8.0.1: Type casting can fail in resilient parsing mode. Invalid defaults will not prevent showing help text.
Changed in version 8.0: Looks at ctx.default_map first.
Changed in version 8.0: Added the call parameter.
Parameters
ctx:ContextCurrent context.
call:boolIf the default is a callable, call it. Disable to return the callable instead.
Returns
t.Optional[t.Union[t.Any, t.Callable[[], t.Any]]]Undocumented
def get_help_record(self, ctx):

Undocumented

Parameters
ctx:ContextUndocumented
Returns
t.Optional[t.Tuple[str, str]]Undocumented
def prompt_for_value(self, ctx):
This is an alternative flow that can be activated in the full value processing if a value does not exist. It will prompt the user until a valid value exists and then returns the processed value as result.
Parameters
ctx:ContextUndocumented
Returns
t.AnyUndocumented
def resolve_envvar_value(self, ctx):

Undocumented

Parameters
ctx:ContextUndocumented
Returns
t.Optional[str]Undocumented
def to_info_dict(self):

Gather information that could be useful for a tool generating user-facing documentation.

Use click.Context.to_info_dict to traverse the entire CLI structure.

New in version 8.0.
Returns
t.Dict[str, t.Any]Undocumented
def value_from_envvar(self, ctx):

Undocumented

Parameters
ctx:ContextUndocumented
Returns
t.Optional[t.Any]Undocumented
param_type_name: str =

Undocumented

_flag_needs_value =

Undocumented

allow_from_autoenv =

Undocumented

confirmation_prompt =

Undocumented

count =

Undocumented

default: int =

Undocumented

flag_value: t.Any =

Undocumented

help =

Undocumented

hidden =

Undocumented

hide_input =

Undocumented

is_bool_flag =

Undocumented

is_flag: bool =

Undocumented

prompt =

Undocumented

prompt_required =

Undocumented

show_choices =

Undocumented

show_default =

Undocumented

show_envvar =

Undocumented

type =

Undocumented