Declic (DEcorator-oriented CLI Creator) is a tiny Python 3 package for creating command line interfaces
Project description
Declic (DEcorator-oriented CLI Creator) is a tiny Python 3 package for creating command line interfaces using decorators. It was inspired by the click package and is based on argparse.
Installation
>From PyPI:
pip install declic
or from Github:
pip install git+https://github.com/Septaris/declic.git
Usage
Here is an example of Declic usage:
from declic import group, argument, command
# on_before callbacks are executed if:
# - the group itself is called
# - if any of the child of the group is called
def before_bar():
print('before bar')
def before_sub(tata):
print('before sub: %s' % tata)
# define the root command (a group)
@group(description='my description', on_before=before_bar)
@argument('--version', action='version', version='<the version>')
@argument('--foo', type=int, default=1)
def bar():
print('bar')
# define a sub-group
@bar.group(invokable=True, on_before=before_sub)
@argument('--toto', type=int, default=2)
@argument('--tata', type=str, default='aaa')
def sub(toto, tata):
print('toto: %s' % toto)
print('tata: %s' % tata)
# define a sub-command of the sub-group
# chain option allows to execute each parent group (if they are invokable) before the command call
# each on_before functions will be executed anyway
@sub.command(chain=True)
def mop(toto, **kwargs):
print('kwargs: %s' % kwargs)
print('toto: %s' % toto)
# define a sub-command of the root group
@bar.command()
@argument('-x', type=int, default=1)
@argument('y', type=float)
def foo(x, y):
print(x, y)
if __name__ == '__main__':
import sys
bar(sys.argv[1:])
# or bar()
Running the cli:
$ python my_file.py --help usage: bar [-h] [--foo FOO] [--version] {sub_group,foo} ... my description positional arguments: {sub,foo} optional arguments: -h, --help show this help message and exit --foo FOO --version show program's version number and exit
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
declic-1.0.2.tar.gz
(4.7 kB
view details)
Built Distribution
File details
Details for the file declic-1.0.2.tar.gz
.
File metadata
- Download URL: declic-1.0.2.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a43c07911df2f4ca74a0cb8931fa7984462de92ddcbc90126644255cfaa72613 |
|
MD5 | 512255c7a01be9318f0b6424978773ec |
|
BLAKE2b-256 | dac6b60e5b00681713746c672688ba621e2e753e1701dcad3e6cad376809e0b3 |
File details
Details for the file declic-1.0.2-py3-none-any.whl
.
File metadata
- Download URL: declic-1.0.2-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98030c209f43fb97b72c83b07e8e97966fda80ba660d92967318be15244fcdac |
|
MD5 | fc120f02d335f0ba2241214208136f04 |
|
BLAKE2b-256 | fb258c8f7fdeed0f64986c4903535cb62b9dab9319349641fb9a0d7f70161987 |