Junos-like shell library for Python
Project description
JSH is a Junos-inspired CLI library for your Python apps. If you’ve ever logged into a Junos device, you’ll know how good the CLI is. It offers:
tab-completion, including completion of names of items in the config
help by pressing “?” at any point
completion on pressing either space, tab or enter
JSH attempts to reproduce some of these features (and others) in a Python library based on Readline, to allow you to build better quality CLIs for your apps.
Documentation
Full documentation can be found at RTD.
Installation
Install from PyPI using pip install jsh.
Basic Usage
The library takes a CLI “layout”, which is a dictionary-based tree structure describing your CLI commands. For example, a completely useless CLI with just an exit command, you would define it like this:
import jsh
layout = {
'exit': jsh.exit,
}
cli = jsh.JSH(layout)
while True:
try:
cli.read_and_execute()
except jsh.JSHError as err:
print err
except EOFError:
break
This creates a basic layout with a single available command (exit), passes it to an instance jsh.JSH, and starts an infinite loop, using the read_and_execute method of the JSH CLI object to interact with the user.
This provides a CLI that looks like the following:
> ? Possible completions: exit > ex? Possible completions: exit > exit ? Possible completions: <[Enter]> Execute this command > exit
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file jsh-0.3.3.tar.gz
.
File metadata
- Download URL: jsh-0.3.3.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e5f2cafac521c24f7b912043b1d80d476ab42e0ef9bc28385dece4018067f04 |
|
MD5 | 7091601f549c7375cffee86c854cf09a |
|
BLAKE2b-256 | 7d83f4bb1311204aa097f33b44e4d366351eb351e4a57234346678f2363d43b2 |
File details
Details for the file jsh-0.3.3-py3-none-any.whl
.
File metadata
- Download URL: jsh-0.3.3-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | be2ab15d8d689feb2e8a385a7fa4a84506e23ba06d2d4ae5e09901b6a8d274e8 |
|
MD5 | 4e2be957357ccf8ef79a7980fd4755b4 |
|
BLAKE2b-256 | 97c41f4a0d9d64f62893b5a98423696f57b0aec3249600663300eeab71aede3d |
File details
Details for the file jsh-0.3.3-py2-none-any.whl
.
File metadata
- Download URL: jsh-0.3.3-py2-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fcd376ccfd848f9d498e23f1c729ebd727dba518521b58d17f77e5ecb9abf1bd |
|
MD5 | c1df9aa1e2fa16bc53e2ec53b598e7a7 |
|
BLAKE2b-256 | b053964c39a72c9eab3daaa96c157abf70e872aa453fc18642579e94305dc8a9 |