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
Create a virtual environment using
uv sync
Install the pre-commit hooks using
pre-commit install
Now you have an editable installation, ready to develop.
Testing
After installing all the dependencies, run the test suite using
uv run 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.
Linting and Formatting
The Python code in this repository is linted and formatted using ruff with a line length of 120 characters.
Release files for argparse-shell 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| argparse_shell-0.2.0.tar.gz | 1.1 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| argparse_shell-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.2 MB
Release files / argparse_shell-0.2.0.tar.gz
| Download URL | argparse_shell-0.2.0.tar.gz |
|---|---|
| Size | 1.1 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
04b19e51a14fdfb0041361c845c921a62ebcd75dca3e5644a30c0d059e71fad3
|
|
BLAKE2b-256 checksum How to use checksums |
e39b1aac9a90b8de32a4dec5106e9c03ba516ad3cae6d3450e3afe9233fde149
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.8.22
|
Release files / argparse_shell-0.2.0-py3-none-any.whl
| Download URL | argparse_shell-0.2.0-py3-none-any.whl |
|---|---|
| Size | 18.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b2bd72ccd18711e6dff57092f4ca5bcd2ff0ed52bc8310d6a50326fa07b60631
|
|
BLAKE2b-256 checksum How to use checksums |
1445efe6591118dc147fc0e39c0371d601880543cddf87f4a7c28cc81e0305e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.8.22
|