Groups Module API Reference¶
This section documents the internals of the groups
module in Bijux CLI.
bijux_cli.services.plugins.groups ¶
Provides helpers for defining plugin command groups and autocompletions.
This module offers a convenient, decorator-based API for plugin developers to register command groups and their subcommands. It also includes a factory function for creating dynamic shell completers for command arguments, enhancing the interactive user experience of plugins.
command_group ¶
command_group(
name: str, *, version: str | None = None
) -> Callable[
[str],
Callable[[Callable[..., Any]], Callable[..., Any]],
]
A decorator factory for registering plugin subcommands under a group.
This function is designed to be used as a nested decorator to easily define command groups within a plugin.
Example
A plugin can define a "user" command group with a "create" subcommand like this::
group = command_group("user", version="1.0")
@group(sub="create")
def create_user(username: str):
...
Parameters:
-
name
(str
) –The name of the parent command group (e.g., "user").
-
version
(str | None
, default:None
) –An optional version string for the group.
Returns:
-
Callable[[str], Callable[[Callable[..., Any]], Callable[..., Any]]]
–Callable[[str], Callable[[Callable[..., Any]], Callable[..., Any]]]: A decorator that takes a subcommand name and returns the final decorator for the function.
Source code in src/bijux_cli/services/plugins/groups.py
dynamic_choices ¶
dynamic_choices(
callback: Callable[[], list[str]],
*,
case_sensitive: bool = True,
) -> Callable[[Context, ParameterInfo, str], list[str]]
Creates a Typer
completer from a callback function.
This factory function generates a completer that provides dynamic shell completion choices for a command argument or option.
Example
To provide dynamic completion for a --user
option::
def get_all_users() -> list[str]:
return ["alice", "bob", "carol"]
@app.command()
def delete(
user: str = typer.Option(
...,
autocompletion=dynamic_choices(get_all_users)
)
):
...
Parameters:
-
callback
(Callable[[], list[str]]
) –A no-argument function that returns a list of all possible choices.
-
case_sensitive
(bool
, default:True
) –If True, prefix matching is case-sensitive.
Returns:
-
Callable[[Context, ParameterInfo, str], list[str]]
–A
Typer
completer function.