command_line module

Contains the required classes and various utility methods to allow the addition of 3rd party commands into the command-line portion of the editor.

class command_line.command_api.ComplexCommand(cmd_handler)[source]

Bases: command_line.command_api._CommandBase

Represents a base command that holds sub-commands

classmethod get_subclasses()[source]

Utility function to get all classes that extend this one

Return type:List[Type[ComplexCommand]]
Returns:A list of all subclasses
classmethod help(command_name=None)[source]

Abstract method that prints a detailed description of all the commands held by the base command if called with default arguments. If help is called on a specific command, the subcommand’s name will supplied with command_name

This method expects all information to be printed, nothing returned will be used

Parameters:command_name – The name/identifier of the specific command help was called on, None if help was called on the base command of the ComplexCommand
classmethod short_help()[source]

Abstract method for displaying a short help/summary message about the general purpose of the sub-commands

This method should return a string that is <= 50 characters in length, anything longer will be truncated to 50 characters

Return type:str
class command_line.command_api.Mode(cmd_line_handler)[source]

Bases: object

Represents a configurable state that the command line can enter. This is useful for controlling the execution of various commands

before_execution(command)[source]

Called before the execution of a command. Return True to run the given command, False to halt the execution.

Parameters:command (List[str]) – The command that is to be executed
Return type:bool
enter()[source]

Called when the mode is entered

Return type:bool
Returns:Return False if the mode is not ready to be entered, otherwise return True.
exit()[source]

Called when the mode is exited

Return type:bool
Returns:Return False if the mode is not ready to be exited, otherwise return True. If the exit command is supplied a ‘-f’ argument, then the return value is ignored
class command_line.command_api.SimpleCommand(cmd_handler)[source]

Bases: command_line.command_api._CommandBase

Represents a command that can be executed within the command line

classmethod get_subclasses()[source]

Utility function to get all classes that extend this one

Return type:List[Type[SimpleCommand]]
Returns:A list of all subclasses
help()[source]

Abstract method for displaying a detailed help message about the command

This method expects all information to be printed, nothing returned will be used

run(args)[source]

Abstract method where the command logic is ran when the command is executed

Parameters:args (List[str]) – The arguments of the full command
short_help()[source]

Abstract method for displaying a short help/summary message about the command

This method should return a string that is <= 50 characters in length, anything longer will be truncated to 50 characters

Return type:str
class command_line.command_api.WorldMode(cmd_line_handler, **kwargs)[source]

Bases: command_line.command_api.Mode

before_execution(cmd)[source]

Called before the execution of a command. Return True to run the given command, False to halt the execution.

Parameters:command – The command that is to be executed
Return type:bool
enter()[source]

Called when the mode is entered

Return type:bool
Returns:Return False if the mode is not ready to be entered, otherwise return True.
exit()[source]

Called when the mode is exited

Return type:bool
Returns:Return False if the mode is not ready to be exited, otherwise return True. If the exit command is supplied a ‘-f’ argument, then the return value is ignored
class command_line.command_api._CommandBase(cmd_handler)[source]

Bases: object

Abstract class that both SimpleCommand and ComplexCommand inherit from

Note: Any class that inherits this class won’t be registered as a command, you must inherit from SimpleCommand or ComplexCommand

error(message)[source]

Utility method for printing an error message

Parameters:message (Any) – The error message
get_mode(mode_class)[source]

Method for getting a Mode that the program is in

Parameters:mode_class (Type[Mode]) – The class of the Mode instance to get
Return type:Mode
Returns:The instance of the specified Mode, None if the mode hasn’t been entered
get_shared_data(entry_path)[source]

Allows parsing and access to the shared data pool from a data accessor entry marked by a $

Parameters:entry_path (str) – The path to search for an entry, can start with a “$” but isn’t required to
Return type:Optional[object]
Returns:The value stored at the entry path, or None if the entry path couldn’t be found
in_mode(mode_class)[source]

Method for checking whether the program is in the specified Mode

Parameters:mode_class (Type[Mode]) – The class of the Mode to check for
Return type:bool
Returns:True if the program is in the specified Mode, False otherwise
warning(message)[source]

Utility method for printing a warning message

Parameters:message (Any) – The warning message
command_line.command_api.command(command_name)[source]

Registers a class as a command. If the class’ parent is SimpleCommand, then it will use the abstracted methods. If the class’ parent is ComplexCommand, then any method decorated with the subcommand decorator is registered as a sub-command of the given command name.

Parameters:command_name (str) – The name used to identify the command, or the base command if using ComplexCommand
Return type:Type[Union[SimpleCommand, ComplexCommand]]
command_line.command_api.parse_coordinates(coord)[source]

Utility function for parsing X,Y,Z coordinates from a string

Parameters:coord (str) – The coordinate string to parse
Return type:Optional[Tuple[int, int, int]]
Returns:A tuple of the coordinates as ints in X,Y,Z order
command_line.command_api.subcommand(sub_command_name)[source]

Registers the decorated method as a subcommand of the containing ComplexCommand.

Parameters:sub_command_name (str) – The name/identifier of the subcommand
Return type:Callable[[List[str]], None]