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, Argument

click.Argument with the overrides of _ParameterMixin.

Inherits from Click directly: cloup.Argument is click.Argument itself.

class click_extra.parameters.Option(*args, group=None, **attrs)[source]

Bases: _ParameterMixin, Option

cloup.Option with the overrides of _ParameterMixin.

cloup.Option subclasses click.Option to let an option join a Cloup option group.

Todo

Delete the human_readable_name override and _CLICK_HAS_PARAMETER_SPEC once this package’s Click floor reaches 8.6.0. From that release on, Click names a parameter by Parameter.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.0 only: from that release on, Click reads Parameter.spec in its place, and warns about a subclass that overrides this property.

Below it, Click returns self.name here: 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-cyg announces itself as 'apt_cyg', naming a flag no user can type and none of the two they did. click.Argument already overrides the property for its own reasons, leaving click.Option re-declaring the inherited body verbatim.

" / " is the separator click.Parameter.get_error_hint joins 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: Option

Base class of the options Click Extra implements itself.

Identifies Click Extra’s own options with certainty.

Note

The one Click Extra class carrying the Extra prefix: every other one takes the name of the Click or Cloup class it shadows. The plain Option name belongs to the user-facing wrapper this class subclasses, and the prefix marks Click Extra’s own built-in options apart from it. Command reads that mark: it sorts parameters with isinstance(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 in HelpFormatter._style_bracket_fields(), which uses the structured data from Option.get_help_extra() to identify each field by its label.

Note

Built-in option subclasses share a common shape: their __init__ defaults param_decls to the option’s canonical flags and wires an eager callback via kwargs.setdefault("callback", self.<callback>). Every callback name encodes its role with a verb prefix. The common roles are:

  • set_<key> publishes a resolved value to ctx.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 a ctx helper 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. ConfigOption wires load_conf to read, parse, and merge a configuration file, and NoConfigOption wires check_sibling_config_option to assert that a sibling --config option exists.

add_to_parser(parser, ctx)[source]

Register the option, then give the root logger 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 of JobsOption. 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). See click_extra.logging._hold_invocation_handler for the other rules, and for how the handler leaves.

Return type:

None