click_extra.parameters module¶
classDiagram
Argument <|-- Argument
Option <|-- ExtraOption
Option <|-- Option
_ParameterMixin <|-- Argument
_ParameterMixin <|-- Option
Our own flavor of Option, Argument and parameters.
The helpers that introspect a CLI’s parameters live in
click_extra.param_tools, and the --params option in
click_extra.show_params.
- class click_extra.parameters.Argument(param_decls, required=None, help=None, **attrs)[source]¶
Bases:
_ParameterMixin,Argumentclick.Argumentwith the overrides of_ParameterMixin.Inherits from Click directly:
cloup.Argumentisclick.Argumentitself.
- class click_extra.parameters.Option(*args, group=None, **attrs)[source]¶
Bases:
_ParameterMixin,Optioncloup.Optionwith the overrides of_ParameterMixin.cloup.Optionsubclassesclick.Optionto let an option join a Cloup option group.Todo
Delete the
human_readable_nameoverride and_CLICK_HAS_PARAMETER_SPEConce this package’s Click floor reaches8.6.0. From that release on, Click names a parameter byParameter.spec, added by pallets/click#3877: a deprecation notice then names the option by its longest-prefixed flag.- property human_readable_name: str¶
Every spelling of the option, joined the way Click hints at one.
Declared below Click
8.6.0only: from that release on, Click readsParameter.specin its place, and warns about a subclass that overrides this property.Below it, Click returns
self.namehere: the Python identifier it derived from the declarations, which is the one spelling that appears nowhere on the command line. Left alone, a deprecated--apt-cyg / --no-apt-cygannounces itself as'apt_cyg', naming a flag no user can type and none of the two they did.click.Argumentalready overrides the property for its own reasons, leavingclick.Optionre-declaring the inherited body verbatim." / "is the separatorclick.Parameter.get_error_hintjoins the same spellings with, so a message naming an option reads the same whichever of the two produced it.
- class click_extra.parameters.ExtraOption(*args, group=None, **attrs)[source]¶
Bases:
OptionBase class of the options Click Extra implements itself.
Identifies Click Extra’s own options with certainty.
Note
The one Click Extra class carrying the
Extraprefix: every other one takes the name of the Click or Cloup class it shadows. The plainOptionname belongs to the user-facing wrapper this class subclasses, and the prefix marks Click Extra’s own built-in options apart from it.Commandreads that mark: it sorts parameters withisinstance(param, ExtraOption)to push the built-in options to the end.Note
Bracket fields (envvar, default, range, required) cannot be pre-styled in
get_help_record()because Click’s text wrapper splits lines after the record is returned, which would break ANSI codes that span wrapped boundaries. Styling is instead applied post-wrapping inHelpFormatter._style_bracket_fields(), which uses the structured data fromOption.get_help_extra()to identify each field by its label.Note
Built-in option subclasses share a common shape: their
__init__defaultsparam_declsto the option’s canonical flags and wires an eager callback viakwargs.setdefault("callback", self.<callback>). Every callback name encodes its role with a verb prefix. The common roles are:set_<key>publishes a resolved value toctx.meta(set_color,set_no_color,set_theme,set_telemetry,set_progress,set_accessible,set_zero_exit, the verbosity options’set_level);init_<system>additionally installs actxhelper or records a snapshot (init_timer,init_formatter,init_columns,init_sort);validate_<thing>coerces and validates the raw input (validate_jobs,validate_config);print_*renders output and exits (print_man,print_params,print_and_exit).
A few options own a richer operation and name it with its own verb rather than forcing one of the above.
ConfigOptionwiresload_confto read, parse, and merge a configuration file, andNoConfigOptionwirescheck_sibling_config_optionto assert that a sibling--configoption exists.- add_to_parser(parser, ctx)[source]¶
Register the option, then give the
rootlogger its handler for the run.Any of these options may log, and reports through its records: the level changes of the verbosity options, the status lines and the validation errors of
ConfigOption, the warnings ofJobsOption. A command that carries one of them so prints log records in the style of Click Extra while it runs.Click calls this method on every parameter of a command before it processes any of them, so the handler is in place for the records the first callbacks emit. It is also a step an option goes through on a command of any class, which is what lets one of these options work on a plain
click.command.Nothing is attached while Click only completes or inspects a command line (
ctx.resilient_parsing). Seeclick_extra.logging._hold_invocation_handlerfor the other rules, and for how the handler leaves.- Return type: