mafw.scripts.click_groups

Reusable Click group classes for MAFw command-line interfaces.

This module centralizes the command abbreviation behavior used by the mafw executable and the development tools so nested command groups can inherit the same resolution policy without repeating the cls=... configuration.

Added in version 2.2.

Authors

Bulgheroni Antonio <antonio.bulgheroni@ec.europa.eu>

Classes

AbbreviateGroup([name, commands, ...])

Click group that resolves unique command prefixes.

MAFwGroup([name, commands, ...])

Click group with abbreviation and MAFw-specific exit handling.

class mafw.scripts.click_groups.AbbreviateGroup(name: str | None = None, commands: MutableMapping[str, Command] | Sequence[Command] | None = None, invoke_without_command: bool = False, no_args_is_help: bool | None = None, subcommand_metavar: str | None = None, chain: bool = False, result_callback: Callable[[...], Any] | None = None, **kwargs: Any)[source]

Bases: Group

Click group that resolves unique command prefixes.

group_class

alias of AbbreviateGroup

get_command(ctx: Context, cmd_name: str) Command | None[source]

Return a command by exact name or a unique abbreviation.

resolve_command(ctx: Context, args: list[str]) tuple[str | None, Command | None, list[str]][source]

Return the canonical command name for abbreviated commands.

class mafw.scripts.click_groups.MAFwGroup(name: str | None = None, commands: MutableMapping[str, Command] | Sequence[Command] | None = None, invoke_without_command: bool = False, no_args_is_help: bool | None = None, subcommand_metavar: str | None = None, chain: bool = False, result_callback: Callable[[...], Any] | None = None, **kwargs: Any)[source]

Bases: AbbreviateGroup

Click group with abbreviation and MAFw-specific exit handling.

group_class

alias of AbbreviateGroup

_detect_command_name(args: list[str]) str | None[source]

Return the first subcommand token while skipping root option values.

invoke(ctx: Context) Any[source]

Invoke the command and normalize Click exceptions to MAFw exits.

main(*args: Any, **kwargs: Any) None[source]

Run the CLI and convert returned statuses to process exit codes.

parse_args(ctx: Context, args: list[str]) list[str][source]

Parse arguments and record the selected root command before invoke.