Package: mash-shell
Docs:MAIN|Shell|Reference|Library DocsMash | My Automation ShellAshellthat can be used to for automation and (REST) resource discovery. It can be used as acli,repl. It exposes acompleteprogramminglanguagewith variables, functions, conditions and pipes. The language can be tailored towardsdomain-specificapplications and it has interoperability with Bash. In addition, this repository contains a library of  utilities.Features:ADSLthat can interpret user-defined commands:shell.py.Afile-browser. Query both static datastructures and REST APIs:examples/filesystem.py,AREST clientto browse APIs with a programmatic yet intuitive interface:examples/discoverable_api.py.Anobject parserwhich converts JSON data to Python classes:object_parser.py.AnOAS-generatorfor Python classes:oas.py.A subshell wrapper, to redirect the output of shell scripts:subshell.py.A parallelization framework for load testing:parallel.py.LinksMash language referencePyPIgithubdocsShellpipinstallmash-shell
python-mmashSeesrc/examplesfor advances usage examples.Documentation| Implementation:ShellLanguage:Reference.Table of ContentsUsageCLIFilesystem (CRUD Operations)Usage ExamplesLibrary & ToolsParallelization UtilitiesObject ParserUsageSeereference.CLI▶python-mmash-h
usage:shell.py[-hvsr][-fFILE][--sessionSESSION][cmd[cmd...]]Ifnopositionalargumentsaregiventhenaninteractivesubshellisstarted.

positionalarguments:cmdAcomma-ornewline-separatedlistofcommands

optionalarguments:-h,--helpshowthishelpmessageandexit-v,--verbose-s,--safeSafe-mode.Askforconfirmationbeforeexecutingcommands.-fFILE,--fileFILEReadandrunFILEasacommands-r,--reloadReloadlastsession--sessionSESSIONUsesessionSESSIONFilesystem (CRUD Operations)Seeexamples/filesystem.pyandexamples/discoverable.py.ExampleDescriptioncd [PATH]Change the current working directory. Alias:uselist [PATH]List the items in a directory. Use the current working directory by default. Alias:lget NAMERetrieve a file.set NAME VALUEModify a file.new NAME [NAME..]Create new directories.show [NAME]Display detailed information about a directory.cp,mv,rmModify files. I.e. copy, move, rename or remove files.Usage ExamplesFor real-world examples, seelib.Example 1Seesrc/examples/shell_example.py. It shows how to use a user-definnable mapping of custom functions.
It uses the libraryquoto create a user-friendly subshell with autocompletion prompts.# python3 src/examples/shell_example.py echo 'hello world'helloworldExample 2: REST ClientBrowse through a REST API as if it is mounted as a filesystem.# python3 src/examples/rest_client_implicit.py$cdusers# browse some.api.com/v1/users$get2||values||:------|:-------------------||email|name.2@company.com||name|name_2|$flatten12>>=getusers$email
name.1@company.com
name.2@company.com

$cd-
$tree{'document':'https://dummy-api.com/v1','users':{0:{'email':'name.0@company.com','name':'name_0'},1:{'email':'name.1@company.com','name':'name_1'},2:{'email':'name.2@company.com','name':'name_2'},
...Example 3: CommandsRun commands from a file withpython src/shell -f FILEorpython -m src.shell -f FILE.# write to fileprintAsentence.>out.txt!catout.txt|>exportx# save text from fileprint$xy<-shellexpr2+2# store result in variable $yprint"result:"$y# prints "result: 4shellexpr2+2->z# store result in variable $zprint"result:"$z# prints "result: 4Example 4: File System SimulationSupport both static and dynamic data.With Static DataSeesrc/examples/filesystem_example.py. This simulates a REST resources with a directory hierarchy.
In addition, it provides fuzzy name completion.$pythonsrc/examples/shell_example.pytree# example data with dicts and listsrepository={'worlds':[{'name':'earth','animals':[{'name':'terrestrial','snakes':[{'name':'python'},{'name':'cobra'}]},{'name':'aquatic','penquins':[{'name':'tux'}]}]}]}# note the autocompletion$pythonsrc/examples/filesystem.py'cd world; cd a; cd t; cd snakes; ll'python
cobraWith Dynamic DataSeeexamples/discoverable.py.# list remote/auto-generated data$pythonsrc/examples/discoverable.py'ls'department_805,department_399# refresh data, then save$pysrc/examples/discoverable.py'ls ; save'department_750,department_14# reload data$pythonsrc/examples/discoverable.py'ls'department_750,department_14Library & ToolsRepository structuresrc
├──examples
├──lib# mash shell scripts└──mash├──filesystem# Directory-based datastructures: FileSystem, View├──object_parser# Parse JSON objects└──shell# Shell, ShellWithFileSystemtestSetupUsing aMakefilefor convenience.makeinstall
maketestParallelization UtilitiesSome experiments with parallelization, concurrency andasyncioin Python.TestStart a dummy server.python3src/server.pyDo a simple load testpython3src/parallel.py-vObject Parsersrc/object_parser/object_parser.pyparses JSON data and instantiate Python objects.src/object_parser/oas.pyconverts domain-models to OAS.Examplepythonsrc/object_parser_example.pyREST APIServerpythonsrc/object_parser_server.pyClientcurl-X'POST''http://localhost:5000/v1/organizations'\-H'Content-Type: application/json'\-d'{ "board": [ "string" ], "ceo": "string", "departments": [ { "manager": "string", "teams": [ { "manager": "string", "members": [ "string" ], "team_type": "A", "active": true, "capacity": 0, "value": 0 } ] } ] }'