Create interactive shell programs from arbitrary objects using the argparse and cmd modules
Project description
argparse-shell
Create interactive shell programs from arbitrary objects using the argparse and cmd modules.
Usage
Use the ArgparseShell.from_object
factory method to quickly create an interactive command line interface
for an existing class. Afterwards the application can be run using the ArgparseShell.main
method.
See the following ./examples/calculator.py for a simple example:
#! /usr/bin/env python3
from argparse_shell import ArgparseShell
class Calculator:
"""A simple calculator example"""
def add(self, a: float, b: float) -> float:
"""Add two numbers
:param a: First number
:param b: Second number
:return: Sum of two numbers
"""
return a + b
def div(self, a: float, b: float) -> float:
"""
Divide numbers
:param a: First number
:param b: Second number
:return: Division of two numbers"""
return a / b
def mult(self, a: float, b: float) -> float:
"""Multiply two numbers
:param a: First number
:param b: Second number
:return: Product of two numbers
"""
return a * b
def sub(self, a: float, b: float) -> float:
"""Subtract two numbers
:param a: First number
:type a: float
:param b: Second number
:type b: float
:return: Subtraction of the two numbers
:rtype: float
"""
return a - b
if __name__ == "__main__":
calc = Calculator()
shell = ArgparseShell.from_object(calc, "calc")
shell.main()
Development
Fork the repository from Github
Clone your version of the repository
git clone https://github.com/<your-username>/argparse-shell
Install the dependencies and dev dependencies using
pip install -e .[dev]
Install the pre-commit hooks using
$ pre-commit install
pre-commit installed at .git/hooks/pre-commit
Now you have an editable installation, ready to develop.
Testing
After installing all the dependencies, run the test suite using
pytest
The options for pytest are defined in the setup.cfg and include test coverage check.
The coverage currently has a fail-under
limit of 75 percent. This limit might get increased when more tests get added.
Formatting
The Python code in this repository is formatted using black black with a line length
of 120 characters. The configuration for black is located in the section [tool.black]
section of pyproject.toml.
Linting
Linting is implemented using flake8. The configuration for flake8 is located in
the section [flake8]
of the setup.cfg.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file argparse_shell-0.1.1.tar.gz
.
File metadata
- Download URL: argparse_shell-0.1.1.tar.gz
- Upload date:
- Size: 16.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.10.12 Linux/6.5.0-1017-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e090d056be0fa0c0c4c850b21ac6373e1c439223c3698924237e93329f2bf89 |
|
MD5 | 66b83d804883d7e8030685368c63afcf |
|
BLAKE2b-256 | c0535ea4a22c77c047f1c319fdfd2ed0d965626bd1c0ca84c4ae0ba54db4c5d9 |
File details
Details for the file argparse_shell-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: argparse_shell-0.1.1-py3-none-any.whl
- Upload date:
- Size: 19.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.10.12 Linux/6.5.0-1017-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3a626fc150cb8d141d6bd57f662d51a99f073e83f3480206fcfc2c30bff953c |
|
MD5 | 87a0f60c211ddd4ddc685ee6e46c01f3 |
|
BLAKE2b-256 | 4d3f6a1e6e09685e9018fe289f243cbed7cc9f70b29955959a28152f1e15d9d6 |