wuttjamaican.cli.base

WuttJamaican - core command logic

See also Command Line.

wuttjamaican.cli.base.wutta_typer

This is the top-level wutta command, using the Typer framework.

See also make_typer().

wuttjamaican.cli.base.make_cli_config(ctx: Context)[source]

Make a config object according to the command-line context (params).

This function is normally called by typer_callback().

This function calls make_config() using config files specified via command line (if any).

Parameters:

ctxtyper.Context instance

Returns:

WuttaConfig instance

wuttjamaican.cli.base.make_typer(**kwargs)[source]

Create a Typer command instance, per Wutta conventions.

This function is used to create the top-level wutta command, wutta_typer. You can use it to create additional top-level commands for your app if needed. (And don’t forget to register; see Custom Commands.)

Parameters:

callback – Override for the Typer.callback param. If not specified, typer_callback() is used.

Returns:

typer.Typer instance

wuttjamaican.cli.base.typer_callback(ctx: ~typer.models.Context, config_paths: ~typing.Annotated[~typing.List[~pathlib.Path] | None, <typer.models.OptionInfo object at 0x7f7657145910>] = None)[source]

Generic callback for use with top-level commands. This adds some top-level args:

  • --config (and -c)

This callback is responsible for creating the config object for the command. (It calls make_cli_config() for that.) It then attaches it to the context as ctx.wutta_config.

wuttjamaican.cli.base.typer_eager_imports(group: [<class 'typer.main.Typer'>, <class 'str'>])[source]

Eagerly import all modules which are registered as having subcommands belonging to the given group (i.e. top-level command).

This is used to locate subcommands which may be defined by multiple different packages. It is mostly needed for the main wutta command, since e.g. various extension packages may define additional subcommands for it.

Most custom apps will define their own top-level command and some subcommands, but will have no need to “discover” additional subcommands defined elsewhere. Hence you normally would not need to call this function.

However if you wish to define a wutta subcommand(s), you would need to register the entry point for your module(s) containing the subcommand(s) like so (in pyproject.toml):

[project.entry-points."wutta.typer_imports"]
poser = "poser.commands"

Note that the wutta.typer_imports above indicates you are registering a module which defines wutta subcommands. The poser name is arbitrary but should match your package name.

Parameters:

group – Typer group command, or the name of one.