decree-tree


Namedecree-tree JSON
Version 0.3.0 PyPI version JSON
download
home_pagehttps://gitlab.com/elasmocalc/decree-tree
SummaryA minimal way to create nested argparse-based subcommands in scripts.
upload_time2025-02-02 18:26:31
maintainerJared Ahern
docs_urlNone
authorJared Ahern
requires_python>=3.10
licenseApache-2.0
keywords command cli
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # decree-tree

So you need to create a command-line interface.
Perhaps you are familiar with
[argparse](https://docs.python.org/3/library/argparse.html)
but would like to define subcommands using classes?
Then `decree-tree` can help with that!

The `decree-tree` package provides a lightweight means for defining
nested command-line interfaces, using standard `argparse`-based
parsing wrapped in a flexible class.

## Installation

To install ``decree-tree`` from PyPI via pip, run this shell command
with the proper Python environment active:

```shell
pip install decree-tree
```

If you are using a different package manager, such as Poetry,
use its appropriate installation command for the ``decree-tree``
package on PyPI.

## Usage

To create a command tree, subclass `decree_tree.DecreeTree` create
new commands, then assemble their instances appropriately. For
example, consider this file `command.py`:

```python
from decree_tree import DecreeTree

class Root(DecreeTree):
    def add_arguments(self, parser):
        super().add_arguments(parser)
        parser.add_argument('-v', '--value')

class Echo(DecreeTree):
    def execute(self):
        super().execute()
        print(self.options.value)

class Double(DecreeTree):
    def execute(self):
        super().execute()
        print(self.options.value, self.options.value)

root = Root()
root.add(Echo)
root.add(Double)

if __name__ == '__main__':
    root.run()
```

Invoking script above yields results like the following:

```shell
$ python command.py double -v bark
bark bark
```

This script can be called in many other ways, including
displaying autogenerated help. The behavior is very customizable.

## Documentation

See the full documentation [here](https://elasmocalc.net/decree-tree).

## Status

This package is relatively stable, and has had an initial release, but
is still under initial development.

To contribute, create an issue or submit an MR!

            

Raw data

            {
    "_id": null,
    "home_page": "https://gitlab.com/elasmocalc/decree-tree",
    "name": "decree-tree",
    "maintainer": "Jared Ahern",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "jared.ahern.dev@gmail.com",
    "keywords": "command, cli",
    "author": "Jared Ahern",
    "author_email": "jared.ahern.dev@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/12/4e/40de55abbc385b19301d95a3595b50a8843c9a264d752a337c30e61db8d0/decree_tree-0.3.0.tar.gz",
    "platform": null,
    "description": "# decree-tree\n\nSo you need to create a command-line interface.\nPerhaps you are familiar with\n[argparse](https://docs.python.org/3/library/argparse.html)\nbut would like to define subcommands using classes?\nThen `decree-tree` can help with that!\n\nThe `decree-tree` package provides a lightweight means for defining\nnested command-line interfaces, using standard `argparse`-based\nparsing wrapped in a flexible class.\n\n## Installation\n\nTo install ``decree-tree`` from PyPI via pip, run this shell command\nwith the proper Python environment active:\n\n```shell\npip install decree-tree\n```\n\nIf you are using a different package manager, such as Poetry,\nuse its appropriate installation command for the ``decree-tree``\npackage on PyPI.\n\n## Usage\n\nTo create a command tree, subclass `decree_tree.DecreeTree` create\nnew commands, then assemble their instances appropriately. For\nexample, consider this file `command.py`:\n\n```python\nfrom decree_tree import DecreeTree\n\nclass Root(DecreeTree):\n    def add_arguments(self, parser):\n        super().add_arguments(parser)\n        parser.add_argument('-v', '--value')\n\nclass Echo(DecreeTree):\n    def execute(self):\n        super().execute()\n        print(self.options.value)\n\nclass Double(DecreeTree):\n    def execute(self):\n        super().execute()\n        print(self.options.value, self.options.value)\n\nroot = Root()\nroot.add(Echo)\nroot.add(Double)\n\nif __name__ == '__main__':\n    root.run()\n```\n\nInvoking script above yields results like the following:\n\n```shell\n$ python command.py double -v bark\nbark bark\n```\n\nThis script can be called in many other ways, including\ndisplaying autogenerated help. The behavior is very customizable.\n\n## Documentation\n\nSee the full documentation [here](https://elasmocalc.net/decree-tree).\n\n## Status\n\nThis package is relatively stable, and has had an initial release, but\nis still under initial development.\n\nTo contribute, create an issue or submit an MR!\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "A minimal way to create nested argparse-based subcommands in scripts.",
    "version": "0.3.0",
    "project_urls": {
        "Documentation": "https://elasmocalc.net/decree-tree",
        "Homepage": "https://gitlab.com/elasmocalc/decree-tree",
        "Repository": "https://gitlab.com/elasmocalc/decree-tree",
        "issues": "https://gitlab.com/elasmocalc/decree-tree/issues",
        "pypi": "https://pypi.org/project/decree-tree/"
    },
    "split_keywords": [
        "command",
        " cli"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0fb5ebffecc4294fecdfdf877d3c9f824cc76dd3af0c70f1b0ee86f59709609e",
                "md5": "1f2b7f8a43a04a8a6a3d986fa2939f40",
                "sha256": "66e0e3de080a61e9005fefff30d94de127bd992b980f1220beaec9c8accae50a"
            },
            "downloads": -1,
            "filename": "decree_tree-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1f2b7f8a43a04a8a6a3d986fa2939f40",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 19409,
            "upload_time": "2025-02-02T18:26:29",
            "upload_time_iso_8601": "2025-02-02T18:26:29.949223Z",
            "url": "https://files.pythonhosted.org/packages/0f/b5/ebffecc4294fecdfdf877d3c9f824cc76dd3af0c70f1b0ee86f59709609e/decree_tree-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "124e40de55abbc385b19301d95a3595b50a8843c9a264d752a337c30e61db8d0",
                "md5": "6f22044b2c997200e0c35e0666b04f9f",
                "sha256": "297173af7a7ec3bbbe8610084c456aa4432efb58c55055efa9038ec5ece42f0c"
            },
            "downloads": -1,
            "filename": "decree_tree-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "6f22044b2c997200e0c35e0666b04f9f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 17080,
            "upload_time": "2025-02-02T18:26:31",
            "upload_time_iso_8601": "2025-02-02T18:26:31.713114Z",
            "url": "https://files.pythonhosted.org/packages/12/4e/40de55abbc385b19301d95a3595b50a8843c9a264d752a337c30e61db8d0/decree_tree-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-02 18:26:31",
    "github": false,
    "gitlab": true,
    "bitbucket": false,
    "codeberg": false,
    "gitlab_user": "elasmocalc",
    "gitlab_project": "decree-tree",
    "lcname": "decree-tree"
}
        
Elapsed time: 4.31624s