Documentation
BasePrompter
Base interpreter class.
- class cmdcraft.base.BasePrompter[source]
Bases:
objectPrompter basic command set.
This class offers an operational command set to be embedded into the CLI interpreter.
- property commands: dict
Return the available commands.
- Returns:
Commands dictionary.
- Return type:
dict
- async help(command='help')[source]
Show Cmdcraft interpreter help.
The interpreter receives instructions from the standard input (stdin) to dynamically execute operations on running services.
For further help, type the command help [command].
- Return type:
None- Parameters:
command (str)
- async interpret(cmdline)[source]
Interpret user input.
This method is used to parse input commands, handling eventual failures and raised exceptions.
- Parameters:
cmdline (
str) – Input command as single string line.- Return type:
None
- property is_running: bool
Returns if the execution loop is active.
- Returns:
True if the loop is active, False otherwise.
- Return type:
bool
- async load(file)[source]
Load a command file.
This may be used to recover previously saved command history into the current execution list.
If the provided file path is not absolute, the contents will be loaded from routines folder.
- Parameters:
file (
str) – Filename.- Return type:
None
- async quit()[source]
Stop the execution loop.
This method calls for a graceful exit, waiting the current scheduled commands to execute.
- Return type:
None
- register_command(command, alias=None)[source]
Register a command into the interpreter.
- Parameters:
command (
callable) – Callable.alias (
str|None) – Command alias. Defaults to None.
- Return type:
- async save(file)[source]
Save the current command history to a file.
This may be used to save the current command history as an external file for posterior loading.
If the provided file path is not absolute, the contents will be saved into routines folder.
- Parameters:
file (
str) – Filename.- Return type:
None
Prompter
Prompt Prompter.
- class cmdcraft.prompter.Prompter[source]
Bases:
BasePrompterPrompt Prompter class.
- async clear()
Clear both command history and screen.
- Return type:
None
- property commands: dict
Return the available commands.
- Returns:
Commands dictionary.
- Return type:
dict
- async help(command='help')
Show Cmdcraft interpreter help.
The interpreter receives instructions from the standard input (stdin) to dynamically execute operations on running services.
For further help, type the command help [command].
- Return type:
None- Parameters:
command (str)
- async history()
Show command history.
- Return type:
None
- async interpret(cmdline)
Interpret user input.
This method is used to parse input commands, handling eventual failures and raised exceptions.
- Parameters:
cmdline (
str) – Input command as single string line.- Return type:
None
- property is_running: bool
Returns if the execution loop is active.
- Returns:
True if the loop is active, False otherwise.
- Return type:
bool
- async load(file)
Load a command file.
This may be used to recover previously saved command history into the current execution list.
If the provided file path is not absolute, the contents will be loaded from routines folder.
- Parameters:
file (
str) – Filename.- Return type:
None
- async quit()
Stop the execution loop.
This method calls for a graceful exit, waiting the current scheduled commands to execute.
- Return type:
None
- register_command(command, alias=None)
Register a command into the interpreter.
- Parameters:
command (
callable) – Callable.alias (
str|None) – Command alias. Defaults to None.
- Return type:
- async save(file)
Save the current command history to a file.
This may be used to save the current command history as an external file for posterior loading.
If the provided file path is not absolute, the contents will be saved into routines folder.
- Parameters:
file (
str) – Filename.- Return type:
None
- async wait(delay)
Block the execution list for given time.
- Parameters:
delay (
float) – Blocks execution for given time in seconds.- Return type:
None
Command
Callable wrapper for info extraction.
- class cmdcraft.command.Command(cb, alias=None)[source]
Bases:
object- Parameters:
cb (callable)
alias (str | None)
- property alias: str
Return the command alias.
- Returns:
Command alias.
- Return type:
str
- property has_args: bool
Return if the command accepts variadic non-keyword arguments.
- property has_kwargs: bool
Return if the command accepts variadic keyword arguments.
- property keyword_parameters: dict[str, Parameter]
Return a dictionary of positional parameters.
- Returns:
Parameters.
- Return type:
dict[str, Parameter]
- property name: str
Return the command name.
- Returns:
Command name.
- Return type:
str
- parameter(parameter)[source]
Parameter getter.
- Return type:
Parameter|None- Parameters:
parameter (str)
- property parameters: dict[str, Parameter]
Return a dictionary of all parameters.
- Returns:
Parameters.
- Return type:
dict[str, Parameter]
- property positional_parameters: dict[str, Parameter]
Return a dictionary of positional parameters.
- Returns:
Parameters.
- Return type:
dict[str, Parameter]