craft_cli.completion.completion module

Complete a fully set-up dispatcher.

class craft_cli.completion.completion.Option(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Flag

An option flag for compgen.

bashdefault = 1
default = 2
dirnames = 4
filenames = 8
noquote = 16
nosort = 32
nospace = 64
plusdirs = 128
class craft_cli.completion.completion.Action(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Flag

An action flag for compgen.

alias = 1
arrayvar = 2
binding = 4
builtin = 8
command = 16
directory = 32
disabled = 64
enabled = 128
export = 256
file = 512
function = 1024
group = 2048
helptopic = 4096
hostname = 8192
job = 16384
keyword = 32768
running = 65536
service = 131072
setopt = 262144
shopt = 524288
signal = 1048576
user = 2097152
variable = 4194304
craft_cli.completion.completion.get_set_flags(flags: Flag) List[Flag][source]

Get a list of the set flags in a flag enum.

class craft_cli.completion.completion.CompGen(options: ~craft_cli.completion.completion.Option | None = None, actions: ~craft_cli.completion.completion.Action | None = None, glob_pattern: str | None = None, prefix: str | None = None, suffix: str | None = None, words: ~typing.List[str] = <factory>, filter_pattern: str | None = None)[source]

Bases: object

An object that, when converted to a string, generates a compgen command.

Excludes ‘-C’ and ‘-F’ options, since they can just as easily be replaced with $(…)

options: Option | None = None
actions: Action | None = None
glob_pattern: str | None = None
prefix: str | None = None
suffix: str | None = None
words: List[str]
filter_pattern: str | None = None
class craft_cli.completion.completion.Arg(flags: List[str], completion_command: str | CompGen)[source]

Bases: ABC

An argument baseclass.

flags: List[str]
completion_command: str | CompGen
classmethod from_global_argument(argument: GlobalArgument) Self[source]

Convert a general GlobalArgument to an OptionArgument for parsing.

classmethod from_action(action: Action) Self[source]

Convert an argparse Action into an OptionArgument for parsing.

abstract property flag_list: str

A list of all flags associated with this argument.

class craft_cli.completion.completion.Argument(flags: List[str], completion_command: str | CompGen)[source]

Bases: Arg

A simple argument.

property flag_list: str

A list of all flags associated with this argument.

class craft_cli.completion.completion.OptionArgument(flags: List[str], completion_command: str | CompGen)[source]

Bases: Arg

An argument that’s an option.

property flag_list: str

A list of all flags associated with this argument.

class craft_cli.completion.completion.CommandMapping(options: List[OptionArgument], args: List[Argument], params: str | CompGen)[source]

Bases: object

A utility class containing all arguments for a command.

options: List[OptionArgument]
args: List[Argument]
params: str | CompGen
property all_args: str

All arguments, joined by spaces.

craft_cli.completion.completion.complete(shell_cmd: str, get_app_info: Callable[[], Tuple[Dispatcher, Dict[str, Any] | None]]) str[source]

Generate a bash completion script based on a craft-cli dispatcher.

Parameters:
  • shell_cmd – The name of the command being completed for

  • get_app_info – A function that returns a populated craft-cli dispatcher and the config

needed to create its commands :return: A bash completion script for shell_cmd

craft_cli.completion.completion.main() None[source]

Entry point for bash completion script generation.