Skip to content
Back to top
View this page
Edit this page

# xonsh.completers.click

Tab-completion for click-based aliases registered via `xonsh.aliases.Aliases.register_click_command()`.

The entry point is `complete_click()`, bound per-alias through `functools.partial(complete_click, click_cmd)` and attached to the alias wrapper as `xonsh_complete`. The stock alias completer (`xonsh.completers._aliases.complete_aliases`) then picks it up from `alias.func.xonsh_complete` during normal tab completion.

The `click` package is imported lazily — this module is only exercised once a click alias has been registered, which itself requires click to be installed.

xonsh.completers.click.complete_click(click_cmd, command, alias=None, **_)

  Tab-completer for click-based aliases.

  Yields completions for, in priority order:

  1. Option values when the preceding token is an option with a `click.Choice` type (`--color <TAB>` → `red green blue`).

  2. Option flags when the prefix starts with `-` (`--nam<TAB>` → `--name`).

  3. Sub-command names when the current command is a `click.Group`.

  4. Positional arguments with a `click.Choice` type.

  Bound per-alias via `functools.partial()` in `xonsh.aliases._click_command_alias()`, so each wrapper captures its own `click.Command` instance.

xonsh.completers.click.option_all_opts(param)

  Every flag string declared on a `click.Option` — primary + secondary. `secondary_opts` holds the off-switch of flag pairs like `--verbose/--quiet`.

xonsh.completers.click.option_takes_value(param)

  `True` if the option consumes a separate argument as its value. Flags (`--verbose`) and count options (`-vvv`) do not.

xonsh.completers.click.positional_index(current_cmd, args_after_cmd)

  Count how many positional arguments have been supplied to `current_cmd` so far, skipping options and their values. Used to pick which `click.Argument` slot we’re completing into.

xonsh.completers.click.previous_option_waiting_value(current_cmd, args_after_cmd)

  If the last token is an option expecting a value, return that `click.Option`; otherwise `None`. Used to drive Choice completion after things like `--color <TAB>`.

xonsh.completers.click.resolve_subcommand(root_cmd, args)

  Walk `click.Group` → sub-command chain consuming positional tokens.

  Returns `(current_cmd, remaining_args)` where `remaining_args` is the slice of `args` belonging to `current_cmd` (i.e. everything after the last recognised sub-command name).

  Options are skipped when they appear before the sub-command name — the few that take a separate value consume the next token as well. An unknown sub-command stops the walk, so the completer can still offer `--` options on the outermost unresolved command.