Documentation

BasePrompter

Base interpreter class.

class cmdcraft.base.BasePrompter[source]

Bases: object

Prompter basic command set.

This class offers an operational command set to be embedded into the CLI interpreter.

async clear()[source]

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')[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 history()[source]

Show command history.

Return type:

None

async init()[source]

Init the interpreter object.

Return type:

None

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

abstractmethod output(*args)[source]

Output command.

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:

Command

async run()[source]

Run Prompter main loop.

Return type:

None

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

async wait(delay)[source]

Block the execution list for given time.

Parameters:

delay (float) – Blocks execution for given time in seconds.

Return type:

None

Prompter

Prompt Prompter.

class cmdcraft.prompter.Prompter[source]

Bases: BasePrompter

Prompt 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

completer()[source]

Process interpreter completer.

Return type:

None

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 init()[source]

Init the interpreter object.

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

output(*args)[source]

Output command.

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:

Command

async run()[source]

Run Prompter main loop.

Return type:

None

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

eval(*args)[source]

Evaluate a call.

Returns:

A future of this callable.

Return type:

Future

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]

process()[source]

Process the callable metadata.

Return type:

None