semvec/pypi-packages huggingface dataset:
decree-tree 0.3.0
A minimal way to create nested argparse-based subcommands in scripts.
License: Apache-2.0
Requires Python: >=3.10
Keywords: command, cli

# 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!