yera.cli.decorators

App-resource decorator helpers for CLI commands.

Symbols

class AppResource — Resources that CLI commands can require or tolerate loading.
def config_for — Return the application resources required by a command function.
def requires — Declare the application resources required by a CLI command.
def tolerates — Declare configuration resources whose loading failures a command tolerates.
def tolerates_for — Return the configuration resources tolerated by a command function.

AppResource

Inherits: Flag

Resources that CLI commands can require or tolerate loading.

config_for

config_for(
    function: Callable,
) → AppResource

Return the application resources required by a command function.

Parameters

function
type: Callable

Command function whose resource metadata should be inspected.

Returns

type: AppResource

The combined required-resource flags, or an empty flag when the function declares no required resources.

requires

requires(
    *resources,
) → Callable[[Callable], Callable]

Declare the application resources required by a CLI command.

Parameters

*resources
type: AppResource = ()

Resources that must be loaded before the command runs.

Returns

type: Callable[[Callable], Callable]

A decorator that attaches the required-resource metadata to a command function.

tolerates

tolerates(
    *resources,
) → Callable[[Callable], Callable]

Declare configuration resources whose loading failures a command tolerates.

Tolerated resources may be inspected when available, but a failure to load them does not prevent the command from running.

Parameters

*resources
type: AppResource = ()

Resources whose loading failures the command can tolerate.

Returns

type: Callable[[Callable], Callable]

A decorator that attaches the tolerated-resource metadata to a command function.

Raises

ValueError

If a resource is declared as both required and tolerated when the returned decorator is applied.

tolerates_for

tolerates_for(
    function: Callable,
) → AppResource

Return the configuration resources tolerated by a command function.

Parameters

function
type: Callable

Command function whose resource metadata should be inspected.

Returns

type: AppResource

The combined tolerated-resource flags, or an empty flag when the function declares no tolerated resources.