recline.repl.shell module

Original © NetApp 2024

This is the main staring point for a recline application

recline.repl.shell.execute(current_input: str) int

Execute the input as a series of commands

recline.repl.shell.relax(argv: str | None = None, program_name: str | None = None, motd: Callable[[], str] | str | None = None, history_file: str | None = None, prompt: str | None = None, repl_mode: bool = True, single_command: str | None = None) None

This is the main entry point of a recline-based application. Call this after all of your commands have been defined.

This will start the application in its REPL mode (by default) or in a single command mode if the first argv to is set to ‘-c’. If in REPL mode, this function will not return until the user quits the application.

Args:
argv: This is a list of arguments that usually comes from the command line.

This will default to sys.argv[1:] but may be overridden if needed.

program_name: If provided, this will be the name of the program (used

internally for display purposes). If not provided, sys.argv[0] will be used as a default (the name of the script file, e.g. hello.py).

motd: If provided, this will be displayed to the user before the prompt.

If it is a string, it will be displayed as given. If it is a callable, then the result will be displayed to the user.

history_file: If persistent command history is desired, a file name may

be passed where a list of the most recent commands will be kept and loaded from.

prompt: This is the prompt to display to the user to let them know that

the system is ready to accept a command. If not provided, a default will be used.

repl_mode: By default, applications using recline expect to act as a REPL

environment where the user will run many commands. These applications can still run a single command if the user passes a -c. But, it is convienent for some applications to act more like a traditional CLI command without needing to pass -c. For those applicatinos, repl_mode can be set to False.

single_command: This acts a bit like non-repl mode, except in this case

the user doesn’t have to pass any command name as an argument to the application, but rather whatever command name is passed here is automatically run and the application exits when the command is complete. If an application only had one command, such as an implementation of ls in Python, then this would be a good choice for exposing that command easily.

recline.repl.shell.run_one_command(current_input: str) int

Parse the current input, search for a matching command and execute it with the given parameters.

recline.repl.shell.setup_tab_complete() None

Set up the readline library to hook into our command completer

recline.repl.shell.track_command_history(filename: str) None

load/save command history