Overview

Library Reference

Reference:

Packages

Internal Packages

Packages

Main Classes (Summary)

Filesystem

Object Parser

Shell

Main Classes (Expanded)

class mash.filesystem.FileSystem(root: dict = None, home: ~typing.List[str | int] | str | int = None, get_hook: ~typing.Callable[[str | int, ~mash.filesystem.view.View], str | int] = <function first>, post_cd_hook: ~typing.Callable = <function none>, **dict_kwds)[source]

A filesystem-like interface for static and dynamic data. This can be used to e.g. browse REST APIs.

append(k, v)[source]

Associate key k with value v and then change the working directory to k

cd(*path: str | int)[source]

Change working directory to path.

cp(*references: str | int)[source]

Copy references.

Usage

cp(a, b) # Let b point to the value referenced by a.
cp(*a, b) # let b contain the pointers *a.
property cwd: View

A shallow copy of the current working directory.

foreach(path: List[str | int] | str | int) List[List[str | int] | str | int][source]

List all objects in the dir associated with each path, recursively.

Usage:

# GET repository/users/{id}/email
foreach repository users email >>= echo 'email:' $
get(path: List[str | int] | str | int, relative=True)[source]

Return the value of the file associated with path.

in_home() bool[source]

Check whether home is in cwd.

ll(*path: str, delimiter='\n', include_list_indices=False) str[source]

Return a formatted result of ls().

ls(*paths: List[str | int] | str | int) List[str | int][source]

List all objects in the dir associated with each path. If this dir is a path, then its properties are returned. Objects that start with HIDE_PREFIX are ignored.

mv(*references: str | int)[source]

Move references.

Usage

mv(a, b) # rename the reference a to b.
mv(*a, b) # move references *a to b
rm(*references: str | int)[source]

Remove references.

property semantic_path: Iterable[str | int]

Convert indices in path to semantic values.

set(k, value: dict | list, cwd: View = None)[source]

Assign a value to the file k.

class mash.filesystem.Discoverable(*args, get_value_method: Callable[[FileSystem, str | int, dict | list, View], dict | list] | str = None, **kwds)[source]
show(*path: str)[source]

Show contents

class mash.filesystem.view.View(tree: dict | list, _trace: ~typing.List[~typing.Tuple[str | int, dict | list]] = <factory>)[source]

A tree of dict’s. Tree traversal is exposed through the methods up and down.

get(k: str | int = None) Tuple[str | int, Any][source]

Return the value that is refrences by k. May raises ValueError.

property trace: List[Tuple[str | int, dict | list]]

A copy of the interal field _trace.

up() str | int[source]

Change view the parent directory. Raises IndexError if there is not parent directory.

class mash.filesystem.Option(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Filesystem traversal options.

default = '~'
home = '~'
root = '/'
stay = '.'
switch = '-'
up = '..'
upup = '...'
upupup = '....'
mash.filesystem.OPTIONS = ['~', '/', '.', '-', '..', '...', '....']

Built-in mutable sequence.

If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.

mash.object_parser.build(cls: type, json: dict)[source]

Initialize cls with fields from data.

class mash.object_parser.BuildError[source]
class mash.object_parser.BuildErrors[source]
class mash.object_parser.ErrorMessages[source]

A static class with can be subclassed

class mash.object_parser.OAS(*args, **kwds)[source]

A key-value map that represents an OAS. It that can be converted to JSON or YAML and viewed in: https://editor.swagger.io/

extend(obj: object)[source]

Generate OAS/Swagger components from a class See: [OAS](https://swagger.io/specification/) E.g.

components:
    schemas:
        User:
            properties:
                id:
                    type: integer
                name:
                    type: string
class mash.shell.ShellWithFileSystem(data={}, repository: FileSystem = None, **kwds)[source]
cd(*path: str)[source]

Change directory and finally reset the current directory. Stay in the current directory by default.

complete_cd(text, line, begidx, endidx)[source]

Filter the result of ls to match text.

foreach(*keys: str, delimiter='\n')[source]

List all objects in the dir associated with each possible path, recursively.

If the path refers to a directory, then return the path to each directory. Otherwise return a list of files.

E.g. do a listing of repository/users/{id}/email.

get(*path: str)[source]

Return the value of the file associated with path.

pwd()[source]

Print the path to the current working directory

set(*args: str)[source]

Assign a value to the file k.

set_cd_aliases()[source]

Add do_{dirname} methods to self.shell for each sub-directory.

unset_cd_aliases()[source]

Remove all custom do_{dirname} methods from self.shell.

use(*path: str)[source]

Access a directory. Change directory in REPL mode, otherwise return the directory.

class mash.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]

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.

onecmd_inner(lines: str)[source]

Override BaseShell.onecmd_inner. Apply a language model iff self.use_model is True.

Parameters

linesstr

The input lines.

class mash.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]

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.

do_env(keys: str)[source]

Retrieve environment variables. Return all variables if no key is given.

do_reload(_)[source]

Reload the current session.

do_save(_)[source]

Save the current session.

do_undo(_)[source]

Undo the previous command

do_unset(args: str)[source]

Unset keys

unset [KEY [KEY..]]
is_function(k: str) bool[source]

Check whether k is an existing function.

is_hidden_function(k: str) bool[source]

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.

is_special_function(char: str) bool[source]

Check whether char is a special characters method

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

reset_locals()[source]

Reset enviornment variables and the current working directory.

run_hidden_function(k: str, args)[source]

Run a hidden function. See base.is_hidden_function

save_session(session='.shell_session.json')[source]

Save the current session to disk.

try_load_session(session='.shell_session.json')[source]

Try to load a session. Ignore errors.

Parameters

sessionstr

The session file to load. If not given, use the default session.

class mash.shell.ShellError[source]
class mash.shell.ShellSyntaxError[source]

Indices and tables