argclz.dispatch.core.Dispatch#
- class argclz.dispatch.core.Dispatch[source]#
Bases:
objectA
dispatch()functions container that it is able to find and run the target function by corresponding name (commandhere).Example
>>> from argclz.dispatch import Dispatch, dispatch ... class Main(Dispatch): ... @dispatch('A') ... def run_a(self): ... ... Main().invoke_command('A')
- __init__()#
Methods Summary
__init__()build_command_usages([group, show_para, ...])Build a help document for
dispatch()functions in this class.find_command(command[, group])find
dispatch()function according to command.invoke_command(command, *args, **kwargs)invoke a
dispatch()function in the default group.invoke_group_command(group, command, *args, ...)invoke a
dispatch()function in a certain group.list_commands([group, all])list all
dispatch()functions.Details
- classmethod list_commands(group=Ellipsis, *, all=False)[source]#
list all
dispatch()functions.- Parameters:
group (str | DispatchGroup | BoundDispatchGroup | None | ellipsis) – dispatch group.
all (bool) – including hidden commands
- Returns:
list of DispatchCommand
- Return type:
- classmethod find_command(command, group=Ellipsis)[source]#
find
dispatch()function according to command.- Parameters:
command (str) – command or one of command’s aliases
group (str | DispatchGroup | BoundDispatchGroup | None | ellipsis) – dispatch group
- Returns:
found
DispatchCommand- Return type:
DispatchCommand | None
- invoke_command(command, *args, **kwargs)[source]#
invoke a
dispatch()function in the default group.- Parameters:
command (str) – command or one of command’s aliases
args – positional arguments of the target function
kwargs – keyword arguments of the target function
- Returns:
target function’s return
- Raises:
- Return type:
- invoke_group_command(group, command, *args, **kwargs)[source]#
invoke a
dispatch()function in a certain group.- Parameters:
group (str | DispatchGroup | BoundDispatchGroup) – dispatch group
command (str) – command or one of command’s aliases
args – positional arguments of the target function
kwargs – keyword arguments of the target function
- Returns:
target function’s return
- Raises:
- Return type:
- classmethod build_command_usages(group=None, *, show_para=False, width=120, doc_indent=20)[source]#
Build a help document for
dispatch()functions in this class.