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, **_)[source]¶
Tab-completer for click-based aliases.
Yields completions for, in priority order:
Option values when the preceding token is an option with a
click.Choicetype (--color <TAB>→red green blue).Option flags when the prefix starts with
-(--nam<TAB>→--name).Sub-command names when the current command is a
click.Group.Positional arguments with a
click.Choicetype.
Bound per-alias via
functools.partial()inxonsh.aliases._click_command_alias(), so each wrapper captures its ownclick.Commandinstance.
- xonsh.completers.click.option_all_opts(param)[source]¶
Every flag string declared on a
click.Option— primary + secondary.secondary_optsholds the off-switch of flag pairs like--verbose/--quiet.
- xonsh.completers.click.option_takes_value(param)[source]¶
Trueif 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)[source]¶
Count how many positional arguments have been supplied to
current_cmdso far, skipping options and their values. Used to pick whichclick.Argumentslot we’re completing into.
- xonsh.completers.click.previous_option_waiting_value(current_cmd, args_after_cmd)[source]¶
If the last token is an option expecting a value, return that
click.Option; otherwiseNone. Used to drive Choice completion after things like--color <TAB>.
- xonsh.completers.click.resolve_subcommand(root_cmd, args)[source]¶
Walk
click.Group→ sub-command chain consuming positional tokens.Returns
(current_cmd, remaining_args)whereremaining_argsis the slice ofargsbelonging tocurrent_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.