recline package

Subpackages

Module contents

Original © NetApp 2024

recline.command(func=None, name: str | None = None, group: str | None = None, aliases: List[str] | None = None, atstart: bool = False, atexit: bool = False, hidden: Callable[[], bool] | bool = False, background: bool = False)

Wrapping a function with this registers it with the recline library and exposes it as a command the user of the application can call.

The name of the command will match the name of the function that is being wrapped. The arguments of the command will match the arguments that the function accepts. Any arguments that are required by the function will be required arguments for the command. Any arguments that are optional (listed as keyword arguments) will be optional for the command.

Args:
name: If the command name shouldn’t inherit the function name, it can be

defined here. This can be especially useful if the command name has spaces in it.

group: If certain commands should be logically grouped together, they

should share the same group name.

aliases: An optional list of other names that will map back to the same

function. For example, if the function was called ‘exit’, a list of aliases might be [‘quit’, ‘q’].

atstart: If set to True, this command will run before the main REPL is

available for processing other commands. If this command fails, the REPL won’t become available.

atexit: Before exiting the program, this command will be run and can be

used to clean up any resources. This command should always take 0 arguments.

hidden: If the command is hidden, then it will not be shown in the help

output or available for autocompletion. It will still be executable by the user if they type it out. This can be either a function which evaluates to True or False, or just a constant True or False.

background: If the command is async and long running, then setting

background to True may be advisable so that other commands can be run in the foreground in the meantime.

recline.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.