A minimal way to create nested argparse-based subcommands in scripts.
Project description
decree-tree
So you need to create a command-line interface.
Perhaps you are familiar with
argparse
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:
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:
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:
$ 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.
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!
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file decree_tree-0.3.0.tar.gz.
File metadata
- Download URL: decree_tree-0.3.0.tar.gz
- Upload date:
- Size: 17.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.0.1 CPython/3.10.16 Darwin/24.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
297173af7a7ec3bbbe8610084c456aa4432efb58c55055efa9038ec5ece42f0c
|
|
| MD5 |
6f22044b2c997200e0c35e0666b04f9f
|
|
| BLAKE2b-256 |
124e40de55abbc385b19301d95a3595b50a8843c9a264d752a337c30e61db8d0
|
File details
Details for the file decree_tree-0.3.0-py3-none-any.whl.
File metadata
- Download URL: decree_tree-0.3.0-py3-none-any.whl
- Upload date:
- Size: 19.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.0.1 CPython/3.10.16 Darwin/24.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
66e0e3de080a61e9005fefff30d94de127bd992b980f1220beaec9c8accae50a
|
|
| MD5 |
1f2b7f8a43a04a8a6a3d986fa2939f40
|
|
| BLAKE2b-256 |
0fb5ebffecc4294fecdfdf877d3c9f824cc76dd3af0c70f1b0ee86f59709609e
|