Parameters¶
Click Extra implements tools to manipulate your CLI’s parameters, options and arguments.
The cornerstone of these tools is the magical --params option, which is a X-ray scanner for your CLI’s parameters.
--params option¶
Click Extra adds a --params flag to every @command and @group. It dumps a colorized table of every parameter, its current value, where that value came from, the resolved environment variable, and the default:
from click_extra import command, option, echo
@command
@option("--int-param1", type=int, default=10)
@option("--int-param2", type=int, default=555)
def cli(int_param1, int_param2):
echo(f"int_param1 is {int_param1!r}")
echo(f"int_param2 is {int_param2!r}")
$ cli --int-param1 3 --params
╭─────────────────────────┬───────────────────────────────────────────────────────────────────────┬────────────────────────────────────────────────┬───────────────────────────────────┬─────────────┬────────┬─────────┬──────────────────┬─────────────────────────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬─────────┬────────────────────┬──────────────┬──────────┬───────┬────────┬─────────────────────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬─────────────╮
│ ID │ Spec. │ Class │ Param type │ Python type │ Hidden │ Exposed │ Allowed in conf? │ Env. vars. │ Default │ Is flag │ Flag value │ Is bool flag │ Multiple │ Nargs │ Prompt │ Confirmation prompt │ Value │ Source │
├─────────────────────────┼───────────────────────────────────────────────────────────────────────┼────────────────────────────────────────────────┼───────────────────────────────────┼─────────────┼────────┼─────────┼──────────────────┼─────────────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼─────────┼────────────────────┼──────────────┼──────────┼───────┼────────┼─────────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼─────────────┤
│ cli._click_default_help │ -h, --help │ click.core.Option │ click.types.BoolParamType │ bool │ ✘ │ ✘ │ ✘ │ CLI__CLICK_DEFAULT_HELP │ False │ ✓ │ True │ ✓ │ ✘ │ 1 │ │ ✘ │ False │ DEFAULT │
│ cli.accessible │ --accessible │ click_extra.accessibility.AccessibleOption │ click.types.BoolParamType │ bool │ ✘ │ ✘ │ ✓ │ CLI_ACCESSIBLE │ False │ ✓ │ True │ ✓ │ ✘ │ 1 │ │ ✘ │ False │ DEFAULT │
│ cli.color │ --color [auto|always|never] │ click_extra.color.ColorOption │ click_extra.color.ColorWhenChoice │ str │ ✘ │ ✘ │ ✓ │ CLI_COLOR │ 'auto' │ ✘ │ 'always' │ ✘ │ ✘ │ 1 │ │ ✘ │ 'auto' │ DEFAULT │
│ cli.config │ --config LOCATION │ click_extra.config.option.ConfigOption │ click.types.UnprocessedParamType │ str │ ✘ │ ✘ │ ✘ │ CLI_CONFIG │ '/home/runner/.config/cli/{*.toml,*.yaml,*.yml,*.json,*.json5,*.jwcc,*.jsonc,*.hjson,*.ini,*.xml,*.plist,*.sqlite,*.sqlite3,*.conf,pyproject.toml}' │ ✘ │ │ ✘ │ ✘ │ 1 │ │ ✘ │ '/home/runner/.config/cli/{*.toml,*.yaml,*.yml,*.json,*.json5,*.jwcc,*.jsonc,*.hjson,*.ini,*.xml,*.plist,*.sqlite,*.sqlite3,*.conf,pyproject.toml}' │ DEFAULT │
│ cli.config │ --no-config │ click_extra.config.option.NoConfigOption │ click.types.UnprocessedParamType │ str │ ✘ │ ✘ │ ✘ │ CLI_CONFIG │ None │ ✓ │ Sentinel.NO_CONFIG │ ✘ │ ✘ │ 1 │ │ ✘ │ None │ DEFAULT │
│ cli.debug │ --debug │ click_extra.logging.DebugOption │ click.types.BoolParamType │ bool │ ✘ │ ✘ │ ✓ │ CLI_DEBUG │ False │ ✓ │ True │ ✓ │ ✘ │ 1 │ │ ✘ │ False │ DEFAULT │
│ cli.export_config │ --export-config FORMAT │ click_extra.config.export.ExportConfigOption │ click.types.Choice │ str │ ✘ │ ✘ │ ✘ │ CLI_EXPORT_CONFIG │ None │ ✘ │ │ ✘ │ ✘ │ 1 │ │ ✘ │ None │ DEFAULT │
│ cli.help_format │ --help-format [carapace|json|json-full|man|markdown|markdown-full] │ click_extra.command_doc.HelpFormatOption │ click_extra.types.EnumChoice │ str │ ✘ │ ✘ │ ✓ │ CLI_HELP_FORMAT │ None │ ✘ │ │ ✘ │ ✘ │ 1 │ │ ✘ │ None │ DEFAULT │
│ cli.int_param1 │ --int-param1 INTEGER │ click_extra.parameters.Option │ click.types.IntParamType │ int │ ✘ │ ✓ │ ✓ │ CLI_INT_PARAM1 │ 10 │ ✘ │ │ ✘ │ ✘ │ 1 │ │ ✘ │ '3' │ COMMANDLINE │
│ cli.int_param2 │ --int-param2 INTEGER │ click_extra.parameters.Option │ click.types.IntParamType │ int │ ✘ │ ✓ │ ✓ │ CLI_INT_PARAM2 │ 555 │ ✘ │ │ ✘ │ ✘ │ 1 │ │ ✘ │ 555 │ DEFAULT │
│ cli.man │ --man │ click_extra.command_doc.ManOption │ click.types.BoolParamType │ bool │ ✘ │ ✘ │ ✓ │ CLI_MAN │ False │ ✓ │ True │ ✓ │ ✘ │ 1 │ │ ✘ │ False │ DEFAULT │
│ cli.no_color │ --no-color │ click_extra.color.NoColorOption │ click.types.BoolParamType │ bool │ ✘ │ ✘ │ ✓ │ CLI_NO_COLOR │ False │ ✓ │ True │ ✓ │ ✘ │ 1 │ │ ✘ │ False │ DEFAULT │
│ cli.params │ --params │ click_extra.show_params.ShowParamsOption │ click.types.BoolParamType │ bool │ ✘ │ ✘ │ ✘ │ CLI_PARAMS │ False │ ✓ │ True │ ✓ │ ✘ │ 1 │ │ ✘ │ True │ COMMANDLINE │
│ cli.progress │ --progress / --no-progress │ click_extra.spinner.ProgressOption │ click.types.BoolParamType │ bool │ ✘ │ ✘ │ ✓ │ CLI_PROGRESS │ True │ ✓ │ True │ ✓ │ ✘ │ 1 │ │ ✘ │ True │ DEFAULT │
│ cli.quiet │ -q, --quiet │ click_extra.logging.QuietOption │ click.types.IntRange │ int │ ✘ │ ✘ │ ✓ │ CLI_QUIET │ 0 │ ✘ │ │ ✘ │ ✘ │ 1 │ │ ✘ │ 0 │ DEFAULT │
│ cli.table_format │ --table-format FORMAT │ click_extra.table_options.TableFormatOption │ click_extra.types.EnumChoice │ str │ ✘ │ ✘ │ ✓ │ CLI_TABLE_FORMAT │ 'rounded-outline' │ ✘ │ │ ✘ │ ✘ │ 1 │ │ ✘ │ 'rounded-outline' │ DEFAULT │
│ cli.theme │ --theme [auto|dark|dracula|light|manpage|monokai|nord|solarized-dark] │ click_extra.theme.ThemeOption │ click_extra.theme.ThemeChoice │ str │ ✘ │ ✘ │ ✓ │ CLI_THEME │ 'dark' │ ✘ │ │ ✘ │ ✘ │ 1 │ │ ✘ │ 'dark' │ DEFAULT │
│ cli.time │ --time / --no-time │ click_extra.execution.TimerOption │ click.types.BoolParamType │ bool │ ✘ │ ✘ │ ✓ │ CLI_TIME │ False │ ✓ │ True │ ✓ │ ✘ │ 1 │ │ ✘ │ False │ DEFAULT │
│ cli.tree │ --tree │ click_extra.tree.TreeOption │ click.types.BoolParamType │ bool │ ✘ │ ✘ │ ✓ │ CLI_TREE │ False │ ✓ │ True │ ✓ │ ✘ │ 1 │ │ ✘ │ False │ DEFAULT │
│ cli.validate_config │ --validate-config LOCATION │ click_extra.config.option.ValidateConfigOption │ click.types.UnprocessedParamType │ str │ ✘ │ ✘ │ ✘ │ CLI_VALIDATE_CONFIG │ None │ ✘ │ │ ✘ │ ✘ │ 1 │ │ ✘ │ None │ DEFAULT │
│ cli.verbose │ -v, --verbose │ click_extra.logging.VerboseOption │ click.types.IntRange │ int │ ✘ │ ✘ │ ✓ │ CLI_VERBOSE │ 0 │ ✘ │ │ ✘ │ ✘ │ 1 │ │ ✘ │ 0 │ DEFAULT │
│ cli.verbosity │ --verbosity LEVEL │ click_extra.logging.VerbosityOption │ click_extra.types.EnumChoice │ str │ ✘ │ ✘ │ ✓ │ CLI_VERBOSITY │ 'WARNING' │ ✘ │ │ ✘ │ ✘ │ 1 │ │ ✘ │ 'WARNING' │ DEFAULT │
│ cli.version │ --version │ click_extra.version.VersionOption │ click.types.BoolParamType │ bool │ ✘ │ ✘ │ ✘ │ CLI_VERSION │ False │ ✓ │ True │ ✓ │ ✘ │ 1 │ │ ✘ │ False │ DEFAULT │
╰─────────────────────────┴───────────────────────────────────────────────────────────────────────┴────────────────────────────────────────────────┴───────────────────────────────────┴─────────────┴────────┴─────────┴──────────────────┴─────────────────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┴─────────┴────────────────────┴──────────────┴──────────┴───────┴────────┴─────────────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┴─────────────╯
--int-param1 shows 3 because it was passed on the command line. --int-param2 falls back to its 555 default. The --params option produces this table dynamically: every value is re-evaluated at invocation time from the current argv, environment, and config files.
Tip
Every command built with @command or @group captures the pre-parsed argv slice on ctx.meta as RAW_ARGS, which --params itself relies on to re-parse the original arguments. See the available keys table to read it from your own callbacks.
Hint
--params always displays all parameters, even those marked as not allowed in conf, bypassing the excluded_params argument. So you can still see the --help, --version, --config and --params options in the table.
Available columns¶
Each row in the table mirrors a single click.Parameter instance. The columns map to its public attributes (plus a handful of Click Extra-specific fields). The table below is auto-generated at build time from ShowParamsOption.TABLE_HEADERS: edit the ColumnSpec.description entries in click_extra/show_params.py to update it.
Column |
Description |
|---|---|
|
Fully-qualified parameter path ( |
|
Option/argument specification string (like |
|
The parameter’s own help text, as written by the CLI author. Opt-in: it is the only column carrying free-form prose, so it stays out of the default table and is selected by ID ( |
|
Fully-qualified class of the parameter: a subclass of |
|
Click value converter class: a subclass of |
|
Python built-in type the parsed value resolves to: |
|
Reflects |
|
Reflects |
|
Click Extra-specific: whether the parameter is reachable from a configuration file. Controlled by |
|
Environment variables read for this parameter: the explicit |
|
Default value returned by |
|
Reflects |
|
Reflects |
|
Reflects |
|
Reflects |
|
Reflects |
|
Reflects |
|
Reflects |
|
Current value of the parameter at invocation time, computed by |
|
Provenance of the resolved value: a |
|
The configuration file the effective value was loaded from, when |
Columns selection¶
Add Click Extra’s columns_option to your CLI so users can pick which columns --params emits, in the order they want, SQL SELECT-style:
$ cli-with-columns --no-color --columns id,is_flag,default,value --params
╭──────────────────────────────────────┬─────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ID │ Is flag │ Default │ Value │
├──────────────────────────────────────┼─────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ cli-with-columns._click_default_help │ ✓ │ False │ False │
│ cli-with-columns.accessible │ ✓ │ False │ False │
│ cli-with-columns.color │ ✘ │ 'auto' │ 'auto' │
│ cli-with-columns.columns │ ✘ │ () │ 'id,is_flag,default,value' │
│ cli-with-columns.config │ ✘ │ '/home/runner/.config/cli-with-columns/{*.toml,*.yaml,*.yml,*.json,*.json5,*.jwcc,*.jsonc,*.hjson,*.ini,*.xml,*.plist,*.sqlite,*.sqlite3,*.conf,pyproject.toml}' │ '/home/runner/.config/cli-with-columns/{*.toml,*.yaml,*.yml,*.json,*.json5,*.jwcc,*.jsonc,*.hjson,*.ini,*.xml,*.plist,*.sqlite,*.sqlite3,*.conf,pyproject.toml}' │
│ cli-with-columns.config │ ✓ │ None │ None │
│ cli-with-columns.debug │ ✓ │ False │ False │
│ cli-with-columns.export_config │ ✘ │ None │ None │
│ cli-with-columns.help_format │ ✘ │ None │ None │
│ cli-with-columns.int_param1 │ ✘ │ 10 │ 10 │
│ cli-with-columns.int_param2 │ ✘ │ 555 │ 555 │
│ cli-with-columns.man │ ✓ │ False │ False │
│ cli-with-columns.no_color │ ✓ │ False │ True │
│ cli-with-columns.params │ ✓ │ False │ True │
│ cli-with-columns.progress │ ✓ │ True │ True │
│ cli-with-columns.quiet │ ✘ │ 0 │ 0 │
│ cli-with-columns.table_format │ ✘ │ 'rounded-outline' │ 'rounded-outline' │
│ cli-with-columns.theme │ ✘ │ 'dark' │ 'dark' │
│ cli-with-columns.time │ ✓ │ False │ False │
│ cli-with-columns.tree │ ✓ │ False │ False │
│ cli-with-columns.validate_config │ ✘ │ None │ None │
│ cli-with-columns.verbose │ ✘ │ 0 │ 0 │
│ cli-with-columns.verbosity │ ✘ │ 'WARNING' │ 'WARNING' │
│ cli-with-columns.version │ ✓ │ False │ False │
╰──────────────────────────────────────┴─────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Unknown IDs raise a BadParameter listing the valid ones (--columns is built on top of the generic MultiChoice type, which does the validation at parse time). The standalone click-extra wrap --params exposes the same option for inspecting third-party CLIs.
One column is opt-in: Help carries each parameter’s own help text, the only free-form prose in the table, and would squeeze every other column out of shape if it showed up uninvited. Select it by ID to get it:
$ cli-with-columns --no-color --columns id,spec,help --params
╭──────────────────────────────────────┬───────────────────────────────────────────────────────────────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ID │ Spec. │ Help │
├──────────────────────────────────────┼───────────────────────────────────────────────────────────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ cli-with-columns._click_default_help │ -h, --help │ Show this message and exit. │
│ cli-with-columns.accessible │ --accessible │ Accessibility mode: disable colors and render tables in a borderless, screen-reader-friendly format. │
│ cli-with-columns.color │ --color [auto|always|never] │ Colorize the output. A bare --color is the same as --color=always. │
│ cli-with-columns.columns │ --columns COLUMNS │ Restrict and reorder table columns, SQL SELECT-style. Comma-separated list of column IDs. Default: all columns in canonical order. │
│ cli-with-columns.config │ --config LOCATION │ Location of the configuration file. Supports local path with glob patterns or remote URL. │
│ cli-with-columns.config │ --no-config │ Ignore all configuration files and only use command line parameters and environment variables. │
│ cli-with-columns.debug │ --debug │ Shorthand for --verbosity DEBUG. │
│ cli-with-columns.export_config │ --export-config FORMAT │ Export the configuration in the selected format to <stdout>, then exit. │
│ cli-with-columns.help_format │ --help-format [carapace|json|json-full|man|markdown|markdown-full] │ Render the command in the given format and exit. │
│ cli-with-columns.int_param1 │ --int-param1 INTEGER │ [default: 10] │
│ cli-with-columns.int_param2 │ --int-param2 INTEGER │ [default: 555] │
│ cli-with-columns.man │ --man │ Read the command's manual page and exit. │
│ cli-with-columns.no_color │ --no-color │ Disable colorization (alias of --color=never). │
│ cli-with-columns.params │ --params │ Show all CLI parameters, their provenance, defaults and value, then exit. │
│ cli-with-columns.progress │ --progress / --no-progress │ Show progress indicators during long operations. Disabled for non-interactive output (pipes, dumb terminals, CI) and by --accessible. │
│ cli-with-columns.quiet │ -q, --quiet │ Decrease the default WARNING verbosity by one level for each additional repetition of the option. │
│ cli-with-columns.table_format │ --table-format FORMAT │ Rendering style of tables. │
│ cli-with-columns.theme │ --theme [auto|dark|dracula|light|manpage|monokai|nord|solarized-dark] │ Color theme used for help screens. │
│ cli-with-columns.time │ --time / --no-time │ Measure and print elapsed execution time. │
│ cli-with-columns.tree │ --tree │ Show the tree of nested subcommands and exit. │
│ cli-with-columns.validate_config │ --validate-config LOCATION │ Validate the configuration file and exit. │
│ cli-with-columns.verbose │ -v, --verbose │ Increase the default WARNING verbosity by one level for each additional repetition of the option. │
│ cli-with-columns.verbosity │ --verbosity LEVEL │ Either CRITICAL, ERROR, WARNING, INFO, DEBUG. │
│ cli-with-columns.version │ --version │ Show the version and exit. │
╰──────────────────────────────────────┴───────────────────────────────────────────────────────────────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
As structured data¶
--params speaks every structured format, which turns the table into a description of the CLI a tool can consume. It is what makes a Click Extra command introspectable by something other than a reader:
$ cli-with-columns --table-format json --columns id,spec,help,default,envvars --params
[
{
"ID": "cli-with-columns._click_default_help",
"Spec.": "-h, --help",
"Help": "Show this message and exit.",
"Default": false,
"Env. vars.": [
"CLI_WITH_COLUMNS__CLICK_DEFAULT_HELP"
]
},
{
"ID": "cli-with-columns.accessible",
"Spec.": "--accessible",
"Help": "Accessibility mode: disable colors and render tables in a borderless, screen-reader-friendly format.",
"Default": false,
"Env. vars.": [
"CLI_WITH_COLUMNS_ACCESSIBLE"
]
},
{
"ID": "cli-with-columns.color",
"Spec.": "--color [auto|always|never]",
"Help": "Colorize the output. A bare --color is the same as --color=always.",
"Default": "auto",
"Env. vars.": [
"CLI_WITH_COLUMNS_COLOR"
]
},
{
"ID": "cli-with-columns.columns",
"Spec.": "--columns COLUMNS",
"Help": "Restrict and reorder table columns, SQL SELECT-style. Comma-separated list of column IDs. Default: all columns in canonical order.",
"Default": "()",
"Env. vars.": [
"CLI_WITH_COLUMNS_COLUMNS"
]
},
{
"ID": "cli-with-columns.config",
"Spec.": "--config LOCATION",
"Help": "Location of the configuration file. Supports local path with glob patterns or remote URL.",
"Default": "/home/runner/.config/cli-with-columns/{*.toml,*.yaml,*.yml,*.json,*.json5,*.jwcc,*.jsonc,*.hjson,*.ini,*.xml,*.plist,*.sqlite,*.sqlite3,*.conf,pyproject.toml}",
"Env. vars.": [
"CLI_WITH_COLUMNS_CONFIG"
]
},
{
"ID": "cli-with-columns.config",
"Spec.": "--no-config",
"Help": "Ignore all configuration files and only use command line parameters and environment variables.",
"Default": null,
"Env. vars.": [
"CLI_WITH_COLUMNS_CONFIG"
]
},
{
"ID": "cli-with-columns.debug",
"Spec.": "--debug",
"Help": "Shorthand for --verbosity DEBUG.",
"Default": false,
"Env. vars.": [
"CLI_WITH_COLUMNS_DEBUG"
]
},
{
"ID": "cli-with-columns.export_config",
"Spec.": "--export-config FORMAT",
"Help": "Export the configuration in the selected format to <stdout>, then exit.",
"Default": null,
"Env. vars.": [
"CLI_WITH_COLUMNS_EXPORT_CONFIG"
]
},
{
"ID": "cli-with-columns.help_format",
"Spec.": "--help-format [carapace|json|json-full|man|markdown|markdown-full]",
"Help": "Render the command in the given format and exit.",
"Default": null,
"Env. vars.": [
"CLI_WITH_COLUMNS_HELP_FORMAT"
]
},
{
"ID": "cli-with-columns.int_param1",
"Spec.": "--int-param1 INTEGER",
"Help": "[default: 10]",
"Default": 10,
"Env. vars.": [
"CLI_WITH_COLUMNS_INT_PARAM1"
]
},
{
"ID": "cli-with-columns.int_param2",
"Spec.": "--int-param2 INTEGER",
"Help": "[default: 555]",
"Default": 555,
"Env. vars.": [
"CLI_WITH_COLUMNS_INT_PARAM2"
]
},
{
"ID": "cli-with-columns.man",
"Spec.": "--man",
"Help": "Read the command's manual page and exit.",
"Default": false,
"Env. vars.": [
"CLI_WITH_COLUMNS_MAN"
]
},
{
"ID": "cli-with-columns.no_color",
"Spec.": "--no-color",
"Help": "Disable colorization (alias of --color=never).",
"Default": false,
"Env. vars.": [
"CLI_WITH_COLUMNS_NO_COLOR"
]
},
{
"ID": "cli-with-columns.params",
"Spec.": "--params",
"Help": "Show all CLI parameters, their provenance, defaults and value, then exit.",
"Default": false,
"Env. vars.": [
"CLI_WITH_COLUMNS_PARAMS"
]
},
{
"ID": "cli-with-columns.progress",
"Spec.": "--progress / --no-progress",
"Help": "Show progress indicators during long operations. Disabled for non-interactive output (pipes, dumb terminals, CI) and by --accessible.",
"Default": true,
"Env. vars.": [
"CLI_WITH_COLUMNS_PROGRESS"
]
},
{
"ID": "cli-with-columns.quiet",
"Spec.": "-q, --quiet",
"Help": "Decrease the default WARNING verbosity by one level for each additional repetition of the option.",
"Default": 0,
"Env. vars.": [
"CLI_WITH_COLUMNS_QUIET"
]
},
{
"ID": "cli-with-columns.table_format",
"Spec.": "--table-format FORMAT",
"Help": "Rendering style of tables.",
"Default": "rounded-outline",
"Env. vars.": [
"CLI_WITH_COLUMNS_TABLE_FORMAT"
]
},
{
"ID": "cli-with-columns.theme",
"Spec.": "--theme [auto|dark|dracula|light|manpage|monokai|nord|solarized-dark]",
"Help": "Color theme used for help screens.",
"Default": "dark",
"Env. vars.": [
"CLI_WITH_COLUMNS_THEME"
]
},
{
"ID": "cli-with-columns.time",
"Spec.": "--time / --no-time",
"Help": "Measure and print elapsed execution time.",
"Default": false,
"Env. vars.": [
"CLI_WITH_COLUMNS_TIME"
]
},
{
"ID": "cli-with-columns.tree",
"Spec.": "--tree",
"Help": "Show the tree of nested subcommands and exit.",
"Default": false,
"Env. vars.": [
"CLI_WITH_COLUMNS_TREE"
]
},
{
"ID": "cli-with-columns.validate_config",
"Spec.": "--validate-config LOCATION",
"Help": "Validate the configuration file and exit.",
"Default": null,
"Env. vars.": [
"CLI_WITH_COLUMNS_VALIDATE_CONFIG"
]
},
{
"ID": "cli-with-columns.verbose",
"Spec.": "-v, --verbose",
"Help": "Increase the default WARNING verbosity by one level for each additional repetition of the option.",
"Default": 0,
"Env. vars.": [
"CLI_WITH_COLUMNS_VERBOSE"
]
},
{
"ID": "cli-with-columns.verbosity",
"Spec.": "--verbosity LEVEL",
"Help": "Either CRITICAL, ERROR, WARNING, INFO, DEBUG.",
"Default": "WARNING",
"Env. vars.": [
"CLI_WITH_COLUMNS_VERBOSITY"
]
},
{
"ID": "cli-with-columns.version",
"Spec.": "--version",
"Help": "Show the version and exit.",
"Default": false,
"Env. vars.": [
"CLI_WITH_COLUMNS_VERSION"
]
}
]
Values come out as native types here (10, not "10"), and the Help column makes each row self-describing. This is the state of one invocation; for the command’s own interface (its description, usage line, subcommands and examples), --help-format covers what a parameter table cannot. Machine-readable help sets the two side by side.
Table format¶
The default table produced by --params can be a bit overwhelming, so you can change its rendering with the --table-format option:
$ cli --table-format vertical --params
***************************[ 1. row ]***************************
ID | cli._click_default_help
Spec. | -h, --help
Class | click.core.Option
Param type | click.types.BoolParamType
Python type | bool
Hidden | ✘
Exposed | ✘
Allowed in conf? | ✘
Env. vars. | CLI__CLICK_DEFAULT_HELP
Default | False
Is flag | ✓
Flag value | True
Is bool flag | ✓
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | False
Source | DEFAULT
***************************[ 2. row ]***************************
ID | cli.accessible
Spec. | --accessible
Class | click_extra.accessibility.AccessibleOption
Param type | click.types.BoolParamType
Python type | bool
Hidden | ✘
Exposed | ✘
Allowed in conf? | ✓
Env. vars. | CLI_ACCESSIBLE
Default | False
Is flag | ✓
Flag value | True
Is bool flag | ✓
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | False
Source | DEFAULT
***************************[ 3. row ]***************************
ID | cli.color
Spec. | --color [auto|always|never]
Class | click_extra.color.ColorOption
Param type | click_extra.color.ColorWhenChoice
Python type | str
Hidden | ✘
Exposed | ✘
Allowed in conf? | ✓
Env. vars. | CLI_COLOR
Default | 'auto'
Is flag | ✘
Flag value | 'always'
Is bool flag | ✘
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | 'auto'
Source | DEFAULT
***************************[ 4. row ]***************************
ID | cli.config
Spec. | --config LOCATION
Class | click_extra.config.option.ConfigOption
Param type | click.types.UnprocessedParamType
Python type | str
Hidden | ✘
Exposed | ✘
Allowed in conf? | ✘
Env. vars. | CLI_CONFIG
Default | '/home/runner/.config/cli/{*.toml,*.yaml,*.yml,*.json,*.json5,*.jwcc,*.jsonc,*.hjson,*.ini,*.xml,*.plist,*.sqlite,*.sqlite3,*.conf,pyproject.toml}'
Is flag | ✘
Flag value |
Is bool flag | ✘
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | '/home/runner/.config/cli/{*.toml,*.yaml,*.yml,*.json,*.json5,*.jwcc,*.jsonc,*.hjson,*.ini,*.xml,*.plist,*.sqlite,*.sqlite3,*.conf,pyproject.toml}'
Source | DEFAULT
***************************[ 5. row ]***************************
ID | cli.config
Spec. | --no-config
Class | click_extra.config.option.NoConfigOption
Param type | click.types.UnprocessedParamType
Python type | str
Hidden | ✘
Exposed | ✘
Allowed in conf? | ✘
Env. vars. | CLI_CONFIG
Default | None
Is flag | ✓
Flag value | Sentinel.NO_CONFIG
Is bool flag | ✘
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | None
Source | DEFAULT
***************************[ 6. row ]***************************
ID | cli.debug
Spec. | --debug
Class | click_extra.logging.DebugOption
Param type | click.types.BoolParamType
Python type | bool
Hidden | ✘
Exposed | ✘
Allowed in conf? | ✓
Env. vars. | CLI_DEBUG
Default | False
Is flag | ✓
Flag value | True
Is bool flag | ✓
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | False
Source | DEFAULT
***************************[ 7. row ]***************************
ID | cli.export_config
Spec. | --export-config FORMAT
Class | click_extra.config.export.ExportConfigOption
Param type | click.types.Choice
Python type | str
Hidden | ✘
Exposed | ✘
Allowed in conf? | ✘
Env. vars. | CLI_EXPORT_CONFIG
Default | None
Is flag | ✘
Flag value |
Is bool flag | ✘
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | None
Source | DEFAULT
***************************[ 8. row ]***************************
ID | cli.help_format
Spec. | --help-format [carapace|json|json-full|man|markdown|markdown-full]
Class | click_extra.command_doc.HelpFormatOption
Param type | click_extra.types.EnumChoice
Python type | str
Hidden | ✘
Exposed | ✘
Allowed in conf? | ✓
Env. vars. | CLI_HELP_FORMAT
Default | None
Is flag | ✘
Flag value |
Is bool flag | ✘
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | None
Source | DEFAULT
***************************[ 9. row ]***************************
ID | cli.int_param1
Spec. | --int-param1 INTEGER
Class | click_extra.parameters.Option
Param type | click.types.IntParamType
Python type | int
Hidden | ✘
Exposed | ✓
Allowed in conf? | ✓
Env. vars. | CLI_INT_PARAM1
Default | 10
Is flag | ✘
Flag value |
Is bool flag | ✘
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | 10
Source | DEFAULT
***************************[ 10. row ]***************************
ID | cli.int_param2
Spec. | --int-param2 INTEGER
Class | click_extra.parameters.Option
Param type | click.types.IntParamType
Python type | int
Hidden | ✘
Exposed | ✓
Allowed in conf? | ✓
Env. vars. | CLI_INT_PARAM2
Default | 555
Is flag | ✘
Flag value |
Is bool flag | ✘
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | 555
Source | DEFAULT
***************************[ 11. row ]***************************
ID | cli.man
Spec. | --man
Class | click_extra.command_doc.ManOption
Param type | click.types.BoolParamType
Python type | bool
Hidden | ✘
Exposed | ✘
Allowed in conf? | ✓
Env. vars. | CLI_MAN
Default | False
Is flag | ✓
Flag value | True
Is bool flag | ✓
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | False
Source | DEFAULT
***************************[ 12. row ]***************************
ID | cli.no_color
Spec. | --no-color
Class | click_extra.color.NoColorOption
Param type | click.types.BoolParamType
Python type | bool
Hidden | ✘
Exposed | ✘
Allowed in conf? | ✓
Env. vars. | CLI_NO_COLOR
Default | False
Is flag | ✓
Flag value | True
Is bool flag | ✓
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | False
Source | DEFAULT
***************************[ 13. row ]***************************
ID | cli.params
Spec. | --params
Class | click_extra.show_params.ShowParamsOption
Param type | click.types.BoolParamType
Python type | bool
Hidden | ✘
Exposed | ✘
Allowed in conf? | ✘
Env. vars. | CLI_PARAMS
Default | False
Is flag | ✓
Flag value | True
Is bool flag | ✓
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | True
Source | COMMANDLINE
***************************[ 14. row ]***************************
ID | cli.progress
Spec. | --progress / --no-progress
Class | click_extra.spinner.ProgressOption
Param type | click.types.BoolParamType
Python type | bool
Hidden | ✘
Exposed | ✘
Allowed in conf? | ✓
Env. vars. | CLI_PROGRESS
Default | True
Is flag | ✓
Flag value | True
Is bool flag | ✓
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | True
Source | DEFAULT
***************************[ 15. row ]***************************
ID | cli.quiet
Spec. | -q, --quiet
Class | click_extra.logging.QuietOption
Param type | click.types.IntRange
Python type | int
Hidden | ✘
Exposed | ✘
Allowed in conf? | ✓
Env. vars. | CLI_QUIET
Default | 0
Is flag | ✘
Flag value |
Is bool flag | ✘
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | 0
Source | DEFAULT
***************************[ 16. row ]***************************
ID | cli.table_format
Spec. | --table-format FORMAT
Class | click_extra.table_options.TableFormatOption
Param type | click_extra.types.EnumChoice
Python type | str
Hidden | ✘
Exposed | ✘
Allowed in conf? | ✓
Env. vars. | CLI_TABLE_FORMAT
Default | 'rounded-outline'
Is flag | ✘
Flag value |
Is bool flag | ✘
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | 'vertical'
Source | COMMANDLINE
***************************[ 17. row ]***************************
ID | cli.theme
Spec. | --theme [auto|dark|dracula|light|manpage|monokai|nord|solarized-dark]
Class | click_extra.theme.ThemeOption
Param type | click_extra.theme.ThemeChoice
Python type | str
Hidden | ✘
Exposed | ✘
Allowed in conf? | ✓
Env. vars. | CLI_THEME
Default | 'dark'
Is flag | ✘
Flag value |
Is bool flag | ✘
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | 'dark'
Source | DEFAULT
***************************[ 18. row ]***************************
ID | cli.time
Spec. | --time / --no-time
Class | click_extra.execution.TimerOption
Param type | click.types.BoolParamType
Python type | bool
Hidden | ✘
Exposed | ✘
Allowed in conf? | ✓
Env. vars. | CLI_TIME
Default | False
Is flag | ✓
Flag value | True
Is bool flag | ✓
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | False
Source | DEFAULT
***************************[ 19. row ]***************************
ID | cli.tree
Spec. | --tree
Class | click_extra.tree.TreeOption
Param type | click.types.BoolParamType
Python type | bool
Hidden | ✘
Exposed | ✘
Allowed in conf? | ✓
Env. vars. | CLI_TREE
Default | False
Is flag | ✓
Flag value | True
Is bool flag | ✓
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | False
Source | DEFAULT
***************************[ 20. row ]***************************
ID | cli.validate_config
Spec. | --validate-config LOCATION
Class | click_extra.config.option.ValidateConfigOption
Param type | click.types.UnprocessedParamType
Python type | str
Hidden | ✘
Exposed | ✘
Allowed in conf? | ✘
Env. vars. | CLI_VALIDATE_CONFIG
Default | None
Is flag | ✘
Flag value |
Is bool flag | ✘
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | None
Source | DEFAULT
***************************[ 21. row ]***************************
ID | cli.verbose
Spec. | -v, --verbose
Class | click_extra.logging.VerboseOption
Param type | click.types.IntRange
Python type | int
Hidden | ✘
Exposed | ✘
Allowed in conf? | ✓
Env. vars. | CLI_VERBOSE
Default | 0
Is flag | ✘
Flag value |
Is bool flag | ✘
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | 0
Source | DEFAULT
***************************[ 22. row ]***************************
ID | cli.verbosity
Spec. | --verbosity LEVEL
Class | click_extra.logging.VerbosityOption
Param type | click_extra.types.EnumChoice
Python type | str
Hidden | ✘
Exposed | ✘
Allowed in conf? | ✓
Env. vars. | CLI_VERBOSITY
Default | 'WARNING'
Is flag | ✘
Flag value |
Is bool flag | ✘
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | 'WARNING'
Source | DEFAULT
***************************[ 23. row ]***************************
ID | cli.version
Spec. | --version
Class | click_extra.version.VersionOption
Param type | click.types.BoolParamType
Python type | bool
Hidden | ✘
Exposed | ✘
Allowed in conf? | ✘
Env. vars. | CLI_VERSION
Default | False
Is flag | ✓
Flag value | True
Is bool flag | ✓
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | False
Source | DEFAULT
Caution
Because both options are eager, the order in which they are passed matters. --table-format must be passed before --params, otherwise it will have no effect.
Color highlighting¶
By default, the table produced by --params is colorized to highlight important bits. If you do not like colors, you can disable them with the --no-color option:
$ cli --no-color --params
╭─────────────────────────┬───────────────────────────────────────────────────────────────────────┬────────────────────────────────────────────────┬───────────────────────────────────┬─────────────┬────────┬─────────┬──────────────────┬─────────────────────────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬─────────┬────────────────────┬──────────────┬──────────┬───────┬────────┬─────────────────────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬─────────────╮
│ ID │ Spec. │ Class │ Param type │ Python type │ Hidden │ Exposed │ Allowed in conf? │ Env. vars. │ Default │ Is flag │ Flag value │ Is bool flag │ Multiple │ Nargs │ Prompt │ Confirmation prompt │ Value │ Source │
├─────────────────────────┼───────────────────────────────────────────────────────────────────────┼────────────────────────────────────────────────┼───────────────────────────────────┼─────────────┼────────┼─────────┼──────────────────┼─────────────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼─────────┼────────────────────┼──────────────┼──────────┼───────┼────────┼─────────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼─────────────┤
│ cli._click_default_help │ -h, --help │ click.core.Option │ click.types.BoolParamType │ bool │ ✘ │ ✘ │ ✘ │ CLI__CLICK_DEFAULT_HELP │ False │ ✓ │ True │ ✓ │ ✘ │ 1 │ │ ✘ │ False │ DEFAULT │
│ cli.accessible │ --accessible │ click_extra.accessibility.AccessibleOption │ click.types.BoolParamType │ bool │ ✘ │ ✘ │ ✓ │ CLI_ACCESSIBLE │ False │ ✓ │ True │ ✓ │ ✘ │ 1 │ │ ✘ │ False │ DEFAULT │
│ cli.color │ --color [auto|always|never] │ click_extra.color.ColorOption │ click_extra.color.ColorWhenChoice │ str │ ✘ │ ✘ │ ✓ │ CLI_COLOR │ 'auto' │ ✘ │ 'always' │ ✘ │ ✘ │ 1 │ │ ✘ │ 'auto' │ DEFAULT │
│ cli.config │ --config LOCATION │ click_extra.config.option.ConfigOption │ click.types.UnprocessedParamType │ str │ ✘ │ ✘ │ ✘ │ CLI_CONFIG │ '/home/runner/.config/cli/{*.toml,*.yaml,*.yml,*.json,*.json5,*.jwcc,*.jsonc,*.hjson,*.ini,*.xml,*.plist,*.sqlite,*.sqlite3,*.conf,pyproject.toml}' │ ✘ │ │ ✘ │ ✘ │ 1 │ │ ✘ │ '/home/runner/.config/cli/{*.toml,*.yaml,*.yml,*.json,*.json5,*.jwcc,*.jsonc,*.hjson,*.ini,*.xml,*.plist,*.sqlite,*.sqlite3,*.conf,pyproject.toml}' │ DEFAULT │
│ cli.config │ --no-config │ click_extra.config.option.NoConfigOption │ click.types.UnprocessedParamType │ str │ ✘ │ ✘ │ ✘ │ CLI_CONFIG │ None │ ✓ │ Sentinel.NO_CONFIG │ ✘ │ ✘ │ 1 │ │ ✘ │ None │ DEFAULT │
│ cli.debug │ --debug │ click_extra.logging.DebugOption │ click.types.BoolParamType │ bool │ ✘ │ ✘ │ ✓ │ CLI_DEBUG │ False │ ✓ │ True │ ✓ │ ✘ │ 1 │ │ ✘ │ False │ DEFAULT │
│ cli.export_config │ --export-config FORMAT │ click_extra.config.export.ExportConfigOption │ click.types.Choice │ str │ ✘ │ ✘ │ ✘ │ CLI_EXPORT_CONFIG │ None │ ✘ │ │ ✘ │ ✘ │ 1 │ │ ✘ │ None │ DEFAULT │
│ cli.help_format │ --help-format [carapace|json|json-full|man|markdown|markdown-full] │ click_extra.command_doc.HelpFormatOption │ click_extra.types.EnumChoice │ str │ ✘ │ ✘ │ ✓ │ CLI_HELP_FORMAT │ None │ ✘ │ │ ✘ │ ✘ │ 1 │ │ ✘ │ None │ DEFAULT │
│ cli.int_param1 │ --int-param1 INTEGER │ click_extra.parameters.Option │ click.types.IntParamType │ int │ ✘ │ ✓ │ ✓ │ CLI_INT_PARAM1 │ 10 │ ✘ │ │ ✘ │ ✘ │ 1 │ │ ✘ │ 10 │ DEFAULT │
│ cli.int_param2 │ --int-param2 INTEGER │ click_extra.parameters.Option │ click.types.IntParamType │ int │ ✘ │ ✓ │ ✓ │ CLI_INT_PARAM2 │ 555 │ ✘ │ │ ✘ │ ✘ │ 1 │ │ ✘ │ 555 │ DEFAULT │
│ cli.man │ --man │ click_extra.command_doc.ManOption │ click.types.BoolParamType │ bool │ ✘ │ ✘ │ ✓ │ CLI_MAN │ False │ ✓ │ True │ ✓ │ ✘ │ 1 │ │ ✘ │ False │ DEFAULT │
│ cli.no_color │ --no-color │ click_extra.color.NoColorOption │ click.types.BoolParamType │ bool │ ✘ │ ✘ │ ✓ │ CLI_NO_COLOR │ False │ ✓ │ True │ ✓ │ ✘ │ 1 │ │ ✘ │ True │ COMMANDLINE │
│ cli.params │ --params │ click_extra.show_params.ShowParamsOption │ click.types.BoolParamType │ bool │ ✘ │ ✘ │ ✘ │ CLI_PARAMS │ False │ ✓ │ True │ ✓ │ ✘ │ 1 │ │ ✘ │ True │ COMMANDLINE │
│ cli.progress │ --progress / --no-progress │ click_extra.spinner.ProgressOption │ click.types.BoolParamType │ bool │ ✘ │ ✘ │ ✓ │ CLI_PROGRESS │ True │ ✓ │ True │ ✓ │ ✘ │ 1 │ │ ✘ │ True │ DEFAULT │
│ cli.quiet │ -q, --quiet │ click_extra.logging.QuietOption │ click.types.IntRange │ int │ ✘ │ ✘ │ ✓ │ CLI_QUIET │ 0 │ ✘ │ │ ✘ │ ✘ │ 1 │ │ ✘ │ 0 │ DEFAULT │
│ cli.table_format │ --table-format FORMAT │ click_extra.table_options.TableFormatOption │ click_extra.types.EnumChoice │ str │ ✘ │ ✘ │ ✓ │ CLI_TABLE_FORMAT │ 'rounded-outline' │ ✘ │ │ ✘ │ ✘ │ 1 │ │ ✘ │ 'rounded-outline' │ DEFAULT │
│ cli.theme │ --theme [auto|dark|dracula|light|manpage|monokai|nord|solarized-dark] │ click_extra.theme.ThemeOption │ click_extra.theme.ThemeChoice │ str │ ✘ │ ✘ │ ✓ │ CLI_THEME │ 'dark' │ ✘ │ │ ✘ │ ✘ │ 1 │ │ ✘ │ 'dark' │ DEFAULT │
│ cli.time │ --time / --no-time │ click_extra.execution.TimerOption │ click.types.BoolParamType │ bool │ ✘ │ ✘ │ ✓ │ CLI_TIME │ False │ ✓ │ True │ ✓ │ ✘ │ 1 │ │ ✘ │ False │ DEFAULT │
│ cli.tree │ --tree │ click_extra.tree.TreeOption │ click.types.BoolParamType │ bool │ ✘ │ ✘ │ ✓ │ CLI_TREE │ False │ ✓ │ True │ ✓ │ ✘ │ 1 │ │ ✘ │ False │ DEFAULT │
│ cli.validate_config │ --validate-config LOCATION │ click_extra.config.option.ValidateConfigOption │ click.types.UnprocessedParamType │ str │ ✘ │ ✘ │ ✘ │ CLI_VALIDATE_CONFIG │ None │ ✘ │ │ ✘ │ ✘ │ 1 │ │ ✘ │ None │ DEFAULT │
│ cli.verbose │ -v, --verbose │ click_extra.logging.VerboseOption │ click.types.IntRange │ int │ ✘ │ ✘ │ ✓ │ CLI_VERBOSE │ 0 │ ✘ │ │ ✘ │ ✘ │ 1 │ │ ✘ │ 0 │ DEFAULT │
│ cli.verbosity │ --verbosity LEVEL │ click_extra.logging.VerbosityOption │ click_extra.types.EnumChoice │ str │ ✘ │ ✘ │ ✓ │ CLI_VERBOSITY │ 'WARNING' │ ✘ │ │ ✘ │ ✘ │ 1 │ │ ✘ │ 'WARNING' │ DEFAULT │
│ cli.version │ --version │ click_extra.version.VersionOption │ click.types.BoolParamType │ bool │ ✘ │ ✘ │ ✘ │ CLI_VERSION │ False │ ✓ │ True │ ✓ │ ✘ │ 1 │ │ ✘ │ False │ DEFAULT │
╰─────────────────────────┴───────────────────────────────────────────────────────────────────────┴────────────────────────────────────────────────┴───────────────────────────────────┴─────────────┴────────┴─────────┴──────────────────┴─────────────────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┴─────────┴────────────────────┴──────────────┴──────────┴───────┴────────┴─────────────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┴─────────────╯
Caution
Because both options are eager, the order in which they are passed matters. --no-color must be passed before --params, otherwise it will have no effect.
Introspecting parameters¶
If you need to dive deeper into parameters and their values, there is a lot of metadata available in the context. Here are some pointers:
from click import option, echo, pass_context
from click_extra import group
@group
@option("--dummy-flag/--no-flag")
@option("--my-list", multiple=True)
@pass_context
def my_cli(ctx, dummy_flag, my_list):
echo(f"dummy_flag is {dummy_flag!r}")
echo(f"my_list is {my_list!r}")
echo(f"Raw parameters: {ctx.meta.get('click_extra.raw_args', [])}")
echo(f"Loaded, default values: {dict(ctx.default_map)}")
echo(f"Values passed to function: {ctx.params}")
@my_cli.command()
@option("--int-param", type=int, default=10)
def subcommand(int_param):
echo(f"int_parameter is {int_param!r}")
Hint
The click_extra.raw_args metadata field in the context referenced above is not a standard feature from Click, but a helper introduced by Click Extra. It is only available with @group and @command decorators.
Now if we feed the following ~/configuration.toml configuration file:
~/configuration.toml¶[my-cli]
verbosity = "WARNING"
dummy_flag = true
my_list = ["item 1", "item #2", "Very Last Item!"]
[my-cli.subcommand]
int_param = 3
Here is what we get:
$ my-cli --config /tmp/tmpblh9fyva/configuration.toml subcommand
Load configuration matching /tmp/tmpblh9fyva/configuration.toml
dummy_flag is True
my_list is ('item 1', 'item #2', 'Very Last Item!')
Raw parameters: ['--config', '/tmp/tmpblh9fyva/configuration.toml', 'subcommand']
Loaded, default values: {'dummy_flag': True, 'my_list': ['item 1', 'item #2', 'Very Last Item!'], 'verbosity': 'WARNING', 'subcommand': {'int_param': 3}}
Values passed to function: {'dummy_flag': True, 'my_list': ('item 1', 'item #2', 'Very Last Item!')}
int_parameter is 3
Introspecting external CLIs¶
The --params option works on your own Click Extra CLIs. To inspect a third-party CLI that doesn’t use Click Extra, use wrap --params, which loads the target and prints the same table without running it:
$ click-extra wrap --params --table-format vertical -- flask run
***************************[ 1. row ]***************************
ID | run._click_default_help
Spec. | --help
Class | click.core.Option
Param type | click.types.BoolParamType
Python type | bool
Hidden | ✘
Exposed | ✘
Env. vars. | FLASK_RUN__CLICK_DEFAULT_HELP
Default | False
Is flag | ✓
Flag value | True
Is bool flag | ✓
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | None
Source |
***************************[ 2. row ]***************************
ID | run.cert
Spec. | --cert PATH
Class | click.core.Option
Param type | flask.cli.CertParamType
Python type | str
Hidden | ✘
Exposed | ✓
Env. vars. | FLASK_RUN_CERT
Default | None
Is flag | ✘
Flag value |
Is bool flag | ✘
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | None
Source |
***************************[ 3. row ]***************************
ID | run.debug
Spec. | --debug / --no-debug
Class | click.core.Option
Param type | click.types.BoolParamType
Python type | bool
Hidden | ✘
Exposed | ✘
Env. vars. | FLASK_RUN_DEBUG
Default | False
Is flag | ✓
Flag value | True
Is bool flag | ✓
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | None
Source |
***************************[ 4. row ]***************************
ID | run.debugger
Spec. | --debugger / --no-debugger
Class | click.core.Option
Param type | click.types.BoolParamType
Python type | bool
Hidden | ✘
Exposed | ✓
Env. vars. | FLASK_RUN_DEBUGGER
Default | None
Is flag | ✓
Flag value | True
Is bool flag | ✓
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | None
Source |
***************************[ 5. row ]***************************
ID | run.exclude_patterns
Spec. | --exclude-patterns PATH
Class | click.core.Option
Param type | flask.cli.SeparatedPathType
Python type | str
Hidden | ✘
Exposed | ✓
Env. vars. | FLASK_RUN_EXCLUDE_PATTERNS
Default | None
Is flag | ✘
Flag value |
Is bool flag | ✘
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | None
Source |
***************************[ 6. row ]***************************
ID | run.extra_files
Spec. | --extra-files PATH
Class | click.core.Option
Param type | flask.cli.SeparatedPathType
Python type | str
Hidden | ✘
Exposed | ✓
Env. vars. | FLASK_RUN_EXTRA_FILES
Default | None
Is flag | ✘
Flag value |
Is bool flag | ✘
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | None
Source |
***************************[ 7. row ]***************************
ID | run.host
Spec. | -h, --host TEXT
Class | click.core.Option
Param type | click.types.StringParamType
Python type | str
Hidden | ✘
Exposed | ✓
Env. vars. | FLASK_RUN_HOST
Default | '127.0.0.1'
Is flag | ✘
Flag value |
Is bool flag | ✘
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | None
Source |
***************************[ 8. row ]***************************
ID | run.key
Spec. | --key FILE
Class | click.core.Option
Param type | click.types.Path
Python type | str
Hidden | ✘
Exposed | ✘
Env. vars. | FLASK_RUN_KEY
Default | None
Is flag | ✘
Flag value |
Is bool flag | ✘
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | None
Source |
***************************[ 9. row ]***************************
ID | run.port
Spec. | -p, --port INTEGER
Class | click.core.Option
Param type | click.types.IntParamType
Python type | int
Hidden | ✘
Exposed | ✓
Env. vars. | FLASK_RUN_PORT
Default | 5000
Is flag | ✘
Flag value |
Is bool flag | ✘
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | None
Source |
***************************[ 10. row ]***************************
ID | run.reload
Spec. | --reload / --no-reload
Class | click.core.Option
Param type | click.types.BoolParamType
Python type | bool
Hidden | ✘
Exposed | ✓
Env. vars. | FLASK_RUN_RELOAD
Default | None
Is flag | ✓
Flag value | True
Is bool flag | ✓
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | None
Source |
***************************[ 11. row ]***************************
ID | run.with_threads
Spec. | --with-threads / --without-threads
Class | click.core.Option
Param type | click.types.BoolParamType
Python type | bool
Hidden | ✘
Exposed | ✓
Env. vars. | FLASK_RUN_WITH_THREADS
Default | True
Is flag | ✓
Flag value | True
Is bool flag | ✓
Multiple | ✘
Nargs | 1
Prompt |
Confirmation prompt | ✘
Value | None
Source |
Parameter structure¶
The table --params prints is the flattened view of a tree, and ParamStructure is what builds it. The same tree is what --config maps a configuration file’s sections onto: a node is a subcommand, a leaf is a parameter, and the path from the root spells the fully-qualified ID.
Take a group with two subcommands:
import click
@click.group
@click.option("--unit", type=click.Choice(("celsius", "fahrenheit")), default="celsius")
def weather(unit):
"""Report the weather of a city."""
@weather.command
@click.option("--days", type=int, default=3)
@click.option("--tag", multiple=True)
@click.argument("city")
def forecast(days, tag, city):
"""Forecast the days to come."""
@weather.command
@click.option("--since", type=click.DateTime())
def history(since):
"""Look back at recorded weather."""
ParamStructure is a mixin: it expects the class using it to settle which parameters the tree covers. Freezing both filters open covers everything.
from click_extra.param_tools import ParamStructure
class Structure(ParamStructure):
excluded_params = frozenset()
included_params = None
params_template then returns the command tree with every leaf nulled out, which is the skeleton a configuration file is expected to fill:
import json
with click.Context(weather):
print(json.dumps(Structure().params_template, indent=2))
{
"weather": {
"unit": null,
"_click_default_help": null,
"forecast": {
"days": null,
"tag": null,
"city": null,
"_click_default_help": null
},
"history": {
"since": null,
"_click_default_help": null
}
}
}
The walk resolves its root command from the active context, which a CLI callback already sits in. Outside of one, a bare click.Context around the group is enough, as above.
params_objects is the same tree with the parameter objects kept at the leaves, which is what a consumer needs to coerce a configuration value or report where one came from:
with click.Context(weather):
structure = Structure()
print(structure.params_objects["weather"]["forecast"])
print(ParamStructure.get_tree_value(structure.params_objects, "weather", "forecast", "days"))
{'days': [<Option days>], 'tag': [<Option tag>], 'city': [<Argument city>], '_click_default_help': [<Option _click_default_help>]}
[<Option days>]
get_tree_value() descends a path in one call, and raises a KeyError when the path leads nowhere. Its counterpart init_tree_dict() builds a nested dict from a path and a leaf.
Fully-qualified IDs¶
Joining a path with PARAM_PATH_SEP produces the ID shown in the ID column of --params, and the same string excluded_params and included_params are matched against. walk_params() yields those paths directly, unfiltered and flat:
from click_extra.param_tools import PARAM_PATH_SEP
with click.Context(weather):
for keys, param in Structure().walk_params():
param_type = ParamStructure.get_param_type(param)
print(f"{PARAM_PATH_SEP.join(keys):26} {param_type.__name__}")
weather.unit str
weather._click_default_help bool
weather.forecast.days int
weather.forecast.tag list
weather.forecast.city str
weather.forecast._click_default_help bool
weather.history.since str
weather.history._click_default_help bool
The second column is get_param_type(), which reduces a Click type to the Python type a configuration file has to carry, through the TYPE_MAP table. A repeatable parameter is a list whatever its items are, a boolean flag is a bool, and an unrecognized custom type falls back to str, since a command line carries nothing else.
--help sits in that tree like any other option, and a subcommand sharing its name with a parameter of the same level is left out of it, since a single path cannot address both. What a consumer does with the tree is its own decision: --params reports every node, while --config narrows it down through excluded_params.