Skip to main content

enhterm

enhterm is an open source, MIT licensed, Cmd-based framework for writing command interpreters.

Build Status Documentation Status

enhterm provides a class that extends cmd.Cmd and which is also intended to be inherited by a user class, with the end purpose being to create a shell.

Functionality provided by this package is split among mixins, allowing you to construct your own base class if EnhTerm is not suitable.

As with cmd.Cmd, the class constructed as described above can be used like so:

from enhterm import EnhTerm

from enhterm.provider.parser.argparser import ArgParser
from enhterm.provider.parser.argparser.commands import register_commands
from enhterm.provider.stream_provider import StreamProvider

# The stream provider by default reads the input from console.
provider = StreamProvider()

# The text entered by the user then needs to be interpreted.
# Here we use an interpreter based on argparse.
provider.parser = ArgParser(provider=provider)
subparsers = provider.parser.add_subparsers()

# Add built-in commands.
register_commands(subparsers)

# Define you own handler.
def do_add(command, integers):
    return sum(integers)

# Add this command to the argparse library.
parser_add = subparsers.add_parser('add')
parser_add.add_argument(
     'integers', metavar='int', nargs='+', type=int,
     help='integers to be summed (space separated list)')
parser_add.set_defaults(func=do_add)


# Construct the terminal.
class MyShell(EnhTerm):
    """
    Simple terminal.

    Has a command that can add integers and another one
    that quits the interpreter.
    """
    def __init__(self):
        super().__init__(providers=provider)


if __name__ == '__main__':
    print("Type 'add 1 2 3 4 5 6 7 8 9' and you should get back 45")
    print("Type '-h' to get back the usage")
    MyShell().cmd_loop()

Install

pip install enhterm

You can also download/clone the source, in which case you have to:

git clone https://github.com/pyl1b/enhterm.git
python setup.py install

To contribute a patch clone the repo, create a new branch, install in develop mode:

python setup.py develop

What is included

Each of the elements below are implemented in a distinct "mixin" class, which mean that you can create your own combination using EnhTerm class as a template.

Command

Allows python strings to be executed as if the user typed the input at the prompt. This is the base for executing commands in a file.

Exit

Provides the exit command that terminates command loop.

Help

Provides the help command which prints information about the use of the command while accounting for custom commands and shortcuts.

Log Level

Allows changing logging verbosity by issuing commands like set loglevel debug.

Macro

Can record, remove, list and execute previously recorded commands.

Messages

Does not expose any commands but provides the class with a standardized way of issuing messages distinct from the logging mechanism.

Run

Allows executing multiple commands from a string or from a file.

Sub-commands

Commands are usually identified by using the first word the user types. This mixin allows for a more natural way of issuing commands like new macro instead of macro new. Other mixins then add subcommands in their __init__ method.

Metadata

Release files for enhterm 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for enhterm 0.2.1
File Size Uploaded Provenance Actions
enhterm-0.2.1.tar.gz 38.8 kB Without provenance Details for enhterm-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for enhterm 0.2.1
File Interpreter ABI Platform Actions
enhterm-0.2.1-py2.py3-none-any.whl Python 2, Python 3 none any Details for enhterm-0.2.1-py2.py3-none-any.whl

Total release size: 96.3 kB

Release files / enhterm-0.2.1.tar.gz

Download URL enhterm-0.2.1.tar.gz
Size 38.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b15a151b6e6a5f5c9ad963ff4e48ba22eee33262760b3b0c2e0cb94150f66e16
BLAKE2b-256 checksum
How to use checksums
6534a160d19ededfaef61410c53df2eaf36fde9e59058efc79d424dedc989c89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.0

Release files / enhterm-0.2.1-py2.py3-none-any.whl

Download URL enhterm-0.2.1-py2.py3-none-any.whl
Size 57.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
cc7be84716bf58816727d72fcc02107344d95b7241fbb87e1fa749f96d5a1430
BLAKE2b-256 checksum
How to use checksums
5313ce1630e16a8056d81a091302a3631a49992d91d8cef185e3454e5fb309a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.0

Security for enhterm 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page