argparse-shell


Nameargparse-shell JSON
Version 0.1.1 PyPI version JSON
download
home_pageNone
SummaryCreate interactive shell programs from arbitrary objects using the argparse and cmd modules
upload_time2024-04-09 12:59:15
maintainerNone
docs_urlNone
authorJonas Ehrlich
requires_python<4.0,>=3.10
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # argparse-shell

Create interactive shell programs from arbitrary objects using the _argparse_ and _cmd_ modules.

![calculator-example-gif](./examples/calculator-example.gif)

## 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](./examples/calculator.py) for a simple example:

``` python
#! /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](https://github.com/jonasehrlich/argparse-shell)

Clone your version of the repository

``` bash
git clone https://github.com/<your-username>/argparse-shell
```

Install the dependencies and dev dependencies using

``` bash
pip install -e .[dev]
```

Install the [pre-commit](https://pre-commit.com/) hooks using

``` bash
$ pre-commit install
pre-commit installed at .git/hooks/pre-commit
```

Now you have an [editable installation](https://pip.pypa.io/en/stable/cli/pip_install/#editable-installs),
ready to develop.

### Testing

After installing all the dependencies, run the test suite using

``` bash
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](https://github.com/psf/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](https://github.com/PyCQA/flake8). The configuration for _flake8_ is located in
the section `[flake8]` of the _setup.cfg_.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "argparse-shell",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": null,
    "author": "Jonas Ehrlich",
    "author_email": "jonas.ehrlich@umsemi.com",
    "download_url": "https://files.pythonhosted.org/packages/c0/53/5ea4a22c77c047f1c319fdfd2ed0d965626bd1c0ca84c4ae0ba54db4c5d9/argparse_shell-0.1.1.tar.gz",
    "platform": null,
    "description": "# argparse-shell\n\nCreate interactive shell programs from arbitrary objects using the _argparse_ and _cmd_ modules.\n\n![calculator-example-gif](./examples/calculator-example.gif)\n\n## Usage\n\nUse the `ArgparseShell.from_object` factory method to quickly create an interactive command line interface\nfor an existing class. Afterwards the application can be run using the `ArgparseShell.main` method.\nSee the following [./examples/calculator.py](./examples/calculator.py) for a simple example:\n\n``` python\n#! /usr/bin/env python3\nfrom argparse_shell import ArgparseShell\n\n\nclass Calculator:\n    \"\"\"A simple calculator example\"\"\"\n\n    def add(self, a: float, b: float) -> float:\n        \"\"\"Add two numbers\n\n        :param a: First number\n        :param b: Second number\n        :return: Sum of two numbers\n        \"\"\"\n        return a + b\n\n    def div(self, a: float, b: float) -> float:\n        \"\"\"\n        Divide numbers\n\n        :param a: First number\n        :param b: Second number\n        :return: Division of two numbers\"\"\"\n        return a / b\n\n    def mult(self, a: float, b: float) -> float:\n        \"\"\"Multiply two numbers\n\n        :param a: First number\n        :param b: Second number\n        :return: Product of two numbers\n        \"\"\"\n        return a * b\n\n    def sub(self, a: float, b: float) -> float:\n        \"\"\"Subtract two numbers\n\n        :param a: First number\n        :type a: float\n        :param b: Second number\n        :type b: float\n        :return: Subtraction of the two numbers\n        :rtype: float\n        \"\"\"\n        return a - b\n\n\nif __name__ == \"__main__\":\n    calc = Calculator()\n    shell = ArgparseShell.from_object(calc, \"calc\")\n    shell.main()\n\n```\n\n## Development\n\nFork the repository from [Github](https://github.com/jonasehrlich/argparse-shell)\n\nClone your version of the repository\n\n``` bash\ngit clone https://github.com/<your-username>/argparse-shell\n```\n\nInstall the dependencies and dev dependencies using\n\n``` bash\npip install -e .[dev]\n```\n\nInstall the [pre-commit](https://pre-commit.com/) hooks using\n\n``` bash\n$ pre-commit install\npre-commit installed at .git/hooks/pre-commit\n```\n\nNow you have an [editable installation](https://pip.pypa.io/en/stable/cli/pip_install/#editable-installs),\nready to develop.\n\n### Testing\n\nAfter installing all the dependencies, run the test suite using\n\n``` bash\npytest\n```\n\nThe options for _pytest_ are defined in the _setup.cfg_ and include test coverage check.\nThe coverage currently has a `fail-under` limit of 75 percent. This limit might get increased when more tests get added.\n\n### Formatting\n\nThe Python code in this repository is formatted using black [black](https://github.com/psf/black) with a line length\nof 120 characters. The configuration for _black_ is located in the section `[tool.black]` section of _pyproject.toml_.\n\n### Linting\n\nLinting is implemented using [flake8](https://github.com/PyCQA/flake8). The configuration for _flake8_ is located in\nthe section `[flake8]` of the _setup.cfg_.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Create interactive shell programs from arbitrary objects using the argparse and cmd modules",
    "version": "0.1.1",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4d3f6a1e6e09685e9018fe289f243cbed7cc9f70b29955959a28152f1e15d9d6",
                "md5": "87a0f60c211ddd4ddc685ee6e46c01f3",
                "sha256": "f3a626fc150cb8d141d6bd57f662d51a99f073e83f3480206fcfc2c30bff953c"
            },
            "downloads": -1,
            "filename": "argparse_shell-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "87a0f60c211ddd4ddc685ee6e46c01f3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 18960,
            "upload_time": "2024-04-09T12:59:13",
            "upload_time_iso_8601": "2024-04-09T12:59:13.937448Z",
            "url": "https://files.pythonhosted.org/packages/4d/3f/6a1e6e09685e9018fe289f243cbed7cc9f70b29955959a28152f1e15d9d6/argparse_shell-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c0535ea4a22c77c047f1c319fdfd2ed0d965626bd1c0ca84c4ae0ba54db4c5d9",
                "md5": "66b83d804883d7e8030685368c63afcf",
                "sha256": "5e090d056be0fa0c0c4c850b21ac6373e1c439223c3698924237e93329f2bf89"
            },
            "downloads": -1,
            "filename": "argparse_shell-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "66b83d804883d7e8030685368c63afcf",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 16279,
            "upload_time": "2024-04-09T12:59:15",
            "upload_time_iso_8601": "2024-04-09T12:59:15.598203Z",
            "url": "https://files.pythonhosted.org/packages/c0/53/5ea4a22c77c047f1c319fdfd2ed0d965626bd1c0ca84c4ae0ba54db4c5d9/argparse_shell-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-09 12:59:15",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "argparse-shell"
}
        
Elapsed time: 0.20134s