shtab#
complete#
def complete(parser: ArgumentParser,
shell: str = "bash",
root_prefix: Opt[str] = None,
preamble: Union[str, Dict[str, str]] = "",
choice_functions: Opt[Any] = None) -> str
- shell: bash/zsh/tcsh
- root_prefix: prefix for shell functions to avoid clashes (default: "_{parser.prog}")
- preamble: mapping shell to text to prepend to generated script (e.g.
{"bash": "_myprog_custom_function(){ echo hello }"}
) - choice_functions: deprecated
N.B. parser.add_argument().complete = ...
can be used to define custom completions (e.g. filenames). See examples/pathcomplete.py.
add_argument_to#
def add_argument_to(parser: ArgumentParser,
option_string: Union[str,
List[str]] = "--print-completion",
help: str = "print shell completion script",
parent: Opt[ArgumentParser] = None,
preamble: Union[str, Dict[str, str]] = "")
- option_string: iff positional (no
-
prefix) thenparser
is assumed to actually be a subparser (subcommand mode) - parent: required in subcommand mode