pash.command

The actual command classes

class pash.command.CascCommand(cmd: str, *aliases, cmds: Optional[List[pash.command.Command]] = None, case_sensitive: bool = True, unknown_key: Callable[[CascCommand, str], None] = <function _def_unkown_key>, callback: Callable[[...], None] = <function _def_unkown_key>, hint: str = '', cbargs: Union[Tuple[()], Tuple[Any]] = (), cbkwargs: Optional[Dict[str, Any]] = None, parent: Optional[pash.command.Command] = None, sep: str = '\s(?:(?=(?:[^"]*"[^"]*")+[^"]*$)|(?=[^"]*$))')

Represents a cascading-command; a command with sub-commands.

cmds

A list of all availabe sub-commands.

Type:List[Command]
sep

The argument separator.

Type:str
unknown_key

The function that will be called, if an unknown sub-command is encountered.

Type:Callable[[CascCommand, str], None]
parse(cmdline)

Parses the cmdline; checks which sub-command should be called.

add_cmd(cmd)

Adds a command to its list of sub-commands.

usage()

Will return a trace to the command + all sub-commands summarized.

add_cmd(cmd: pash.command.Command) → None

Adds a command to the sub-commands list.

parse(cmdline: str) → None

Parses the cmdline; checks what to do with it.

Calls the appropriate sub-commands, etc.

Parameters:cmdline (str) – Not the actual complete cmdline, but the cmdline after the argument that triggered this command.
usage() → str

Returns the trace + options to use with this command.

class pash.command.Command(cmd: str, *aliases, case_sensitive: bool = True, callback: Callable[[...], None] = <function _def_callback>, hint: str = '', cbargs: Union[Tuple[()], Tuple[Any]] = (), cbkwargs: Optional[Dict[str, Any]] = None, parent: Optional[Command] = None)

Represents an actual command, something the user can enter into the shell.

aliases

A list of all the keywords (aliases) that the command has; that will trigger it.

Type:List[str]
case_sensitive

Whether or not the command should respond to both the upper- and lowercase versions of its aliases.

Type:bool
callback

The function that will be called, when the command is executed.

Type:Callable[.., None]
help

A short summary of what the command does.

Type:str
cbargs

Positional arguments that will be passed to the callback function.

Type:Union[Tuple[()], Tuple[Any]]
cbkwargs

Keyword arguments that will be passed to the callback function.

Type:Dict[str, Any]
parent

The command’s supercommand (needed for tracing).

Type:Command
matches(args)

Checks whether or not the command should be triggered by the given cl arguments.

trace(cu=None)

Computes the command trace. The chain of supercommands that is needed to trigger this command.

usage()

Returns a short summary of this commands arguments and trace.

__call__()

Will call the specified callback function.

__str__()

Returns a nicely formatted, short help string for the command.

matches(args: Union[str, List[str]]) → bool

Checks whether or not the command should be triggered by the given cl arguments.

Parameters:args (Union[str, List[str]]) – Either the commandline or the already split arguments.
Returns:Whether or not the command should be executed.
Return type:bool
trace(cu: Optional[Command] = None) → str

Will compute and return the command’s trace.

Recursively goes through the supercommands until it reaches the shell; returns the resulting trace.

Parameters:cu (Optional[Command]) – Since it’s recursive - the current command. Default is None
Returns:The trace (chain of keywords) needed to trigger the command.
Return type:str
usage() → str

Will return how to use the command.