2024-07-30 11:24:26 +02:00
|
|
|
# tiramisu-cmdline-parser
|
|
|
|
|
2018-11-29 22:49:35 +01:00
|
|
|
Python3 parser for command-line options and arguments using Tiramisu engine.
|
2018-11-29 22:47:12 +01:00
|
|
|
|
|
|
|
# simple example
|
|
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2018-11-30 18:47:16 +01:00
|
|
|
from tiramisu_cmdline_parser import TiramisuCmdlineParser
|
2018-11-29 22:47:12 +01:00
|
|
|
from tiramisu import StrOption, BoolOption, SymLinkOption, OptionDescription, \
|
|
|
|
Config
|
2018-11-30 18:47:16 +01:00
|
|
|
parser = TiramisuCmdlineParser()
|
2018-11-29 22:47:12 +01:00
|
|
|
booloption = BoolOption('verbosity',
|
|
|
|
'increase output verbosity',
|
|
|
|
default=False)
|
|
|
|
config = Config(OptionDescription('root', 'root', [StrOption('var',
|
|
|
|
'a string option',
|
|
|
|
properties=('mandatory',
|
|
|
|
'positional')),
|
|
|
|
booloption,
|
|
|
|
SymLinkOption('v', booloption)]))
|
|
|
|
parser.add_arguments(config)
|
|
|
|
parser.parse_args()
|
|
|
|
print('result:', config.value.dict())
|
|
|
|
```
|
|
|
|
|
2018-11-29 22:49:35 +01:00
|
|
|
```bash
|
2018-11-29 22:47:12 +01:00
|
|
|
[gnunux@localhost tiramisu-parser]$ ./prog.py -h
|
|
|
|
usage: prog.py [-h] [-v] var
|
|
|
|
|
|
|
|
positional arguments:
|
|
|
|
var a string option
|
|
|
|
|
|
|
|
optional arguments:
|
|
|
|
-h, --help show this help message and exit
|
|
|
|
-v, --verbosity increase output verbosity
|
|
|
|
```
|
|
|
|
|
2018-11-29 22:49:35 +01:00
|
|
|
```bash
|
2018-11-29 22:47:12 +01:00
|
|
|
[gnunux@localhost tiramisu-parser]$ ./prog.py -v
|
|
|
|
usage: prog.py [-h] [-v] var
|
|
|
|
prog.py: error: the following arguments are required: var
|
|
|
|
```
|
|
|
|
|
2018-11-29 22:49:35 +01:00
|
|
|
```bash
|
2018-11-29 22:47:12 +01:00
|
|
|
[gnunux@localhost tiramisu-parser]$ ./prog.py test
|
|
|
|
result: {'var': 'test', 'verbosity': False, 'v': False}
|
|
|
|
```
|
|
|
|
|
2018-11-29 22:49:35 +01:00
|
|
|
```bash
|
2018-11-29 22:47:12 +01:00
|
|
|
[gnunux@localhost tiramisu-parser]$ ./prog.py -v test
|
|
|
|
result: {'var': 'test', 'verbosity': True, 'v': True}
|
|
|
|
```
|
|
|
|
|
2018-11-29 22:49:35 +01:00
|
|
|
```bash
|
2018-11-29 22:47:12 +01:00
|
|
|
[gnunux@localhost tiramisu-parser]$ ./prog.py --verbosity test
|
|
|
|
result: {'var': 'test', 'verbosity': True, 'v': True}
|
|
|
|
```
|