almanac.commands

class CommandBase(coroutine: Callable[[…], Coroutine[Any, Any, int]], *, name: Optional[str] = None, description: Optional[str] = None, aliases: Optional[Union[str, Iterable[str]]] = None)[source]

Bases: abc.ABC

Encapsulation of a command.

abstract add_alias(*aliases: str)None[source]

Abstract alias appender to allow for access control.

property aliases

Aliases for this command.

property coroutine

The internal coroutine that this command wraps.

property description

A description for this command.

property has_var_kw_arg

Whether this command has a **kwargs argument.

property has_var_pos_arg

Whether this command has a *args argument.

property identifiers

A combination of this command’s name and any of its aliases.

property name

The primary name of this function.

property signature

The signature of the user-written coroutine wrapped by this command.

class FrozenCommand(*args, **kwds)[source]

Bases: almanac.commands.command_base.CommandBase, collections.abc.Mapping, typing.Generic

A command abstraction that does not permit mutation of its fields.

abbreviated_description

A shortened version of this command’s description.

add_alias(*aliases: str)None[source]

Abstract alias appender to allow for access control.

get_unbound_arguments(*args, **kwargs) → Tuple[almanac.arguments.frozen_argument.FrozenArgument, …][source]

Compute a tuple of arguments that would be unbound with the given values.

In the event of an error where the set of provided arguments cannot even be partially applied to the function signature, an empty tuple is returned.

resolved_kwarg_names(kwarg_dict: Dict[str, Any]) → Tuple[Dict[str, Any], Dict[str, Any]][source]

Transform keyword argument names from their display to real values.

Argument display names are those that may have been overriden by the user. To transform a kwarg dict to a form suitable for binding to the original function definition, we must swap out these argument names to match the wrapped coroutine signature.

Any keys in the kwarg_dict argument that do not map to valid argument names will be present in the second dictionary returned.

async run(*args, **kwargs)int[source]

A thin wrapper around this command’s user-provided coroutine.

The return code follows the following pattern:

0 -> No errors occured. Anything else -> Something went wrong.

class MutableCommand(*args, **kwds)[source]

Bases: almanac.commands.command_base.CommandBase, collections.abc.MutableMapping, typing.Generic

A command abstraction that allows for modification of its fields.

The arguments of this command can be accessed via dict-like operations on instances of this class. Of note is that the keys for this dictionary are the argument names of the internal coroutine from this function (in contrast to a FrozenCommand, which is keyed based on a ArgumentBase’s display_name property).

add_alias(*aliases: str)None[source]

Abstract alias appender to allow for access control.

static ensure_command(new_command: Union[almanac.commands.mutable_command.MutableCommand, Callable[[…], Coroutine[Any, Any, int]]])almanac.commands.mutable_command.MutableCommand[source]
freeze()almanac.commands.frozen_command.FrozenCommand[source]

Convert this instance into a FrozenCommand.