shell package¶
Subpackages¶
- shell.ast package
- shell.grammer package
Submodules¶
shell.base module¶
- class shell.base.BaseShell(*args, env: ~typing.Dict[str, ~typing.Any] = None, use_model=True, save_session_prehook=<function identity>, load_session_posthook=<function identity>, **kwds)[source]¶
Bases:
Cmd2
Extend Cmd with various capabilities. This class is restricted to functionality that requires Cmd methods to be overrriden.
Features:
An environment with local and global variable scopes.
Save/load sessions.
Decoration with functions, both at runtime and compile time.
- add_functions(functions: Dict[str, ShellFunction], group_key=None)[source]¶
Add functions to this instance at runtime. Use a key to select a group of functions.
Parameters¶
- functionsdict
A dictionary of functions to add.
- group_keystr
A key to select a group of functions.
Check whether k is an existing hidden function.
- is_inline_function(k: str) bool [source]¶
Check whether k is an existing inline (user-defined) function.
- last_method()[source]¶
Find the method corresponding to the last command run in shell. It has the form: do_{cmd}
Return a the last method if it exists and None otherwise.
- load_session(session: str, strict=True)[source]¶
Load a session.
arameters¶
- sessionstr
The session file to load.
- strictbool
If True, raise an error if the session file is not found.
- postcmd(stop, _)[source]¶
Display the shell_ready_signal to indicate termination to a parent process.
- remove_functions(group_key=None)[source]¶
Remove functions to this instance at runtime. Use a key to select a group of functions
Run a hidden function. See base.is_hidden_function
shell.cmd2 module¶
- class shell.cmd2.Cmd2(completekey='tab', stdin=None, stdout=None)[source]¶
Bases:
Cmd
Extend cmd.Cmd with various capabilities. This class is restricted to functionality that requires Cmd methods to be overrriden.
Features:
Confirmation mode to allow a user to accept or decline commands.
Error handling.
I/O methods: cat, source, print, println, exit
String methods: echo, flatten
Methods:
cmdloop(): An interactive REPL. onecmd(): Run commands ad-hoc.
- completenames_options = []¶
- default(line: str)[source]¶
Called on an input line when the command prefix is not recognized.
If this method is not overridden, it prints an error message and returns.
- ignore_invalid_syntax = False¶
- intro = 'Press ctrl-d to exit, ctrl-c to cancel, ? for help, ! for shell interop.\n-->\n'¶
- mode = 1¶
- onecmd(line: str) bool [source]¶
Parse and run line. Returns 0 on success and None otherwise. May raises ShellSyntaxError.
Parameters¶
- linestr
The commands to run
- onecmd_inner(lines: str)[source]¶
A wrapper for onecmd that can be overridden.
Parameters¶
- linesstr
The command to run
- prompt = '$ '¶
- class shell.cmd2.Mode(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
Enum
- COMPILE = 2¶
- REPL = 1¶
shell.errors module¶
- exception shell.errors.ShellError[source]¶
Bases:
RuntimeError
- exception shell.errors.ShellPipeError[source]¶
Bases:
RuntimeError
- exception shell.errors.ShellSyntaxError[source]¶
Bases:
ShellError
shell.function module¶
- class shell.function.InlineFunction(command: str, args: List[str], func_name: str, multiline: bool = False, line_indent: str = None, inner: List[str] = <factory>)[source]¶
Bases:
object
shell.shell module¶
- class shell.shell.Shell(*args, env: ~typing.Dict[str, ~typing.Any] = None, use_model=True, save_session_prehook=<function identity>, load_session_posthook=<function identity>, **kwds)[source]¶
Bases:
BaseShell
Extend BaseShell with a language model: Support multiline statements, pipes, conditions, variables and inline function definitions.
The language grammer is based on a BNF-based grammer, which is defined in shell.grammer.parser
The AST is implemented here: shell.ast
The language implementation is defined in shell.ast.
- do_map(line='')[source]¶
Apply a function to each item. It can be used as prefix or infix operator.
Usage (prefix)¶
map f x y z
Usage (infix)¶
f x |> map g f x |> map g $ a b f x >>= g
If $ is present, then each line from stdin is inserted there. Otherwise each line is appended.
- shell.shell.add_cli_args(parser: ArgumentParser)[source]¶
- shell.shell.build(functions: Dict[str, ShellFunction] = None, completions: Dict[str, Callable] = None, instantiate=True) Shell [source]¶
Extend the class Shell and create an instance of it. Note that set_functions must be called before instantiating Shell.
- shell.shell.main(shell: Shell = None, functions: Dict[str, ShellFunction] = None, repl=True) Shell [source]¶
- shell.shell.run_command(command='', shell: Shell = None, strict=None)[source]¶
Run a newline-separated string of commands.
Parameters¶
- strictbool
Raise exceptions when encountering invalid syntax.
- shell.shell.set_completions(functions: ~typing.Dict[str, ~typing.Callable], shell=<class 'shell.shell.Shell'>)[source]¶
- shell.shell.set_functions(functions: ~typing.Dict[str, ~mash.shell.function.ShellFunction], cls: ~cmd.Cmd = <class 'shell.shell.Shell'>) type [source]¶
Extend cls with a set of functions Note that this modifies the class Shell directly, rather than an instance.
- shell.shell.setup(shell: Shell = None, functions: Dict[str, ShellFunction] = None, completions: Dict[str, Callable] = None) Tuple[Shell, List[str], str] [source]¶
Setup an instance of Shell with any given cli options.
First initialize Shell with functions and completions. Then apply any relevant cli options.
shell.with_filesystem module¶
ABC
- class shell.with_filesystem.ShellWithFileSystem(data={}, repository: FileSystem = None, **kwds)[source]¶
Bases:
object
- cd(*path: str)[source]¶
Change directory and finally reset the current directory. Stay in the current directory by default.
Module contents¶
See shell