shellac - Interactive Command Interpreter¶
Shellac¶
shellac is an alternative to the standard python library cmd which aims to offer an alternative approach to nesting commands.
-
class
shellac.
Shellac
(completekey='tab', stdin=<_io.TextIOWrapper name='<stdin>' mode='r' encoding='UTF-8'>, stdout=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>)[source]¶ Bases:
object
An interactive command interpreter. You should never call this class directly. To use it, inherit from this class and implement do_*() methods which map to * commands. Implement child methods of classes defined in your subclass to create subcommands in the interface.
Parameters: - completekey (readline name of a comlpetion key.) – Key to execute completion
- stdin (File-like object) – Override stdin (defaults to sys.stdin)
- stdout (File-like object) – Override stdout (defaults to sys.stdout)
-
static
call_static
(func, *args, **kwargs)[source]¶ Call a method defined using @staticmethod.
Because we want to define completion functions in their associated class and we want them to be static methods we cannot call them directly. Make sure a callable object is called.
-
cancel
(prompt=False)[source]¶ Update the shell to indicate a ‘cancel’.
Parameters: prompt (boolean) – If True, force a redraw of the prompt & line.
-
cmdloop
()[source]¶ Implement an interactive command interpreter which grabs a line of input and passes it to onecmd() until the postcmd() function returns True.
This method will also:
Execute a preloop() method before starting the interpreter
Install a complete() readline completer function
- Write the string intro followed by a newline to stdout
Read from a list of commands called cmdqueue, or
- Read from stdin, and
- Call precmd() with the line as an argument,
- Call onecmd() with the line as an argument,
- Call postcmd() with the stop flag and the line as an argument.
Finally, restore the previous readline completer, if any.
-
complete
¶
-
ctrl_c
(exc)[source]¶ Hook method called when Ctrl-C is pressed during execution of loop body.
Can be overridden.
-
do_EOF
(args)¶ Exit the interactive interpreter.
-
emptyline
()[source]¶ Method to specify what happens when an empty line is entered.
Can be overridden.
-
onecmd
(line, args='', root=None)[source]¶ Execute a single command line.
If the given line is False (i.e. empty), call return the result of emptyline(). Thereafter, try to find a chain of do_*() methods and classes which ends with a callable, then return the result of calling it.
Parameters: - line (string) – line to be executed
- args (string) – used to store ‘current’ part of line during recursion
- root (object) – ‘current’ ‘do_‘ class or method during recursion
-
postcmd
(stop, line)[source]¶ Hook method executed just after a command dispatch is finished.
Can be overridden.
Parameters: - stop (None or True) – flag passed in from onecmd() which is usually returned
- line (string) – line executed by onecmd
Returns: Return True (stop) to cause oneloop() to break
-
postloop
()[source]¶ Hook method executed once when the cmdloop() method is finished.
Can be overridden
-
shellac.
complete_list
(names, token, append_character=' ')[source]¶ Filter given list which starts with the given string.
Parameters: - names (list) – list to filter
- token (string) – ‘startswith’ filter token
- append_character (string) – completion character to append (see rl.completion.append_character)
Returns: generator