shtab#
FILE#
DIRECTORY#
glob#
def glob(*patterns: str) -> CompleteType
Example: glob("*.yml", "*.yaml")
Consider native shell alternatives in special cases:
- any file:
shtab.FILE(instead ofglob("*")) - any directory:
shtab.DIRECTORY(instead ofglob("*/"))
cmd#
def cmd(command: str) -> CompleteType
- command: shell command to run to generate completions
Example: cmd("git branch")
complete#
def complete(parser: ArgumentParser,
shell: str = "bash",
root_prefix: Opt[str] = None,
preamble: str = "",
choice_functions: Opt[Any] = None) -> str
- shell: bash/zsh/tcsh/fish
- root_prefix: prefix for shell functions to avoid clashes (default: "_{parser.prog}")
- preamble: text to prepend to generated script (e.g.
"_myprog_custom_function(){ echo hello }"). Consider usingparser.add_argument().complete = shtab.cmd("echo hello")instead. - choice_functions: deprecated
NOTE: 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) thenparseris assumed to actually be a subparser (subcommand mode) - parent: required in subcommand mode
- preamble: see
completefor details