add a simple example
This commit is contained in:
parent
82d8186062
commit
4c528c0a17
1 changed files with 58 additions and 1 deletions
59
README.md
59
README.md
|
@ -1,3 +1,60 @@
|
|||
# tiramisu-cmdline-parser
|
||||
|
||||
Python3 parser for command-line options and arguments using Tiramisu engine.
|
||||
Parser for command-line options and arguments using Tiramisu engine.
|
||||
|
||||
# simple example
|
||||
|
||||
|
||||
```python
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from tiramisu_parser import TiramisuParser
|
||||
from tiramisu import StrOption, BoolOption, SymLinkOption, OptionDescription, \
|
||||
Config
|
||||
parser = TiramisuParser()
|
||||
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())
|
||||
```
|
||||
|
||||
```
|
||||
[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
|
||||
```
|
||||
|
||||
```
|
||||
[gnunux@localhost tiramisu-parser]$ ./prog.py -v
|
||||
usage: prog.py [-h] [-v] var
|
||||
prog.py: error: the following arguments are required: var
|
||||
```
|
||||
|
||||
```
|
||||
[gnunux@localhost tiramisu-parser]$ ./prog.py test
|
||||
result: {'var': 'test', 'verbosity': False, 'v': False}
|
||||
```
|
||||
|
||||
```
|
||||
[gnunux@localhost tiramisu-parser]$ ./prog.py -v test
|
||||
result: {'var': 'test', 'verbosity': True, 'v': True}
|
||||
```
|
||||
|
||||
```
|
||||
[gnunux@localhost tiramisu-parser]$ ./prog.py --verbosity test
|
||||
result: {'var': 'test', 'verbosity': True, 'v': True}
|
||||
```
|
||||
|
|
Loading…
Reference in a new issue