Skip to content

shtab#

complete#

def complete(parser: ArgumentParser,
             shell: str = "bash",
             root_prefix: Opt[str] = None,
             preamble: Union[str, Dict] = "",
             choice_functions: Opt[Any] = None) -> str
  • parser: argparse.ArgumentParser
  • shell: str (bash/zsh)
  • root_prefix: str or None
    prefix for shell functions to avoid clashes (default: "_{parser.prog}")
  • preamble: dict or str
    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,
                    option_string="--print-completion",
                    help="print shell completion script",
                    parent=None,
                    preamble="")
  • parser: argparse.ArgumentParser
  • option_string: str or list[str]
    iff positional (no - prefix) then parser is assumed to actually be a subparser (subcommand mode)
  • help: str
  • parent: argparse.ArgumentParser
    required in subcommand mode