argclz.dispatch.core.DispatchCommand#

class argclz.dispatch.core.DispatchCommand[source]#

Bases: NamedTuple

The information of dispatch() function. Use dispatch() instead. Do not create this class directly.

__init__()#

Methods Summary

__init__()

parameters()

information of command's parameters

__call__(zelf, *args, **kwargs)

invoke commands.

Attributes Summary

aliases

secondary command

command

primary command

commands

all acceptable commands

doc

document of the command.

func

target function

group

dispatch group

hidden

Is it hidden?

order

order of this command shown in the help document

usage

usage line of this command

validators

parameter validators

Details

group: str | None#

dispatch group

command: str#

primary command

aliases: tuple[str, ...]#

secondary command

order: float#

order of this command shown in the help document

usage: str | None#

usage line of this command

func: Callable[[...], Any]#

target function

validators: dict[str, Callable[[str], Any]]#

parameter validators

hidden: bool#

Is it hidden?

property commands: list[str]#

all acceptable commands

parameters()[source]#

information of command’s parameters

Return type:

list[CommandParameter]

property doc: str | None#

document of the command.

__call__(zelf, *args, **kwargs)[source]#

invoke commands.

parameter pre-processing

If any argument in args is a str that matches ‘name=value’ patterns, it will be parsed into a keyword argument. It allows use key=value pattern in commandline without knowing the position of the parameter.

parameter post-processing

If any argument has a validator (by validator_for()), the argument will be casted to desired type (if it is a str) and be validated. An ValueError will be raised when validation fail.

Parameters:
  • zelf (Any) – instance of the target function

  • args (Any) – positional arguments of the target function

  • kwargs (Any) – keyword arguments of the target function

Returns:

target function’s return

Return type:

Any