Command line based argument parse framework.
Project description
Installing
pip3 install flagopt
Battleship
import flagopt
usage = '-x [spot] -y [spot]'
flags = flagopt.trace(usage)
content = '-x C -y 7'
args = flagopt.snip(flags, content)
print('hit at', args['-x'], args['-y'])
Actions
import flagopt
flags = {
'-move': {
'-x': 'distance',
'-y': 'distance'
},
'-craft': 'recipe',
'-scavenge': {
'-target': 'resource',
'-finish': {
'-time': 'hours',
'-time': 'amount'
}
},
'-rest': 'hours',
'-target': 'human | animal'
}
# show how to use this
usage = flagopt.draw(flags)
command = (
# move right linearly
'-move -x 10 '
# then move diagonally right and down;
# no need to explicitly pass the first flag (-x)
'-move 5 -y -5 '
# backslash is used as an escape character;
# -target will be ignored during the first parse scan
# and the backslash will be removed so that -target can
# be considered during the next scan for -scavenge;
# multiple backslashed can be used to achieve other
# amounts of iterations for this effect
'-scavenge \-target wood '
# arguments can be passed multiple times (-time);
# scavenge for 3 hours and 60 more wood after that
'-finish -time 3 -limit 60 '
# or until 5 hours have passed
'-finish -time 5'
# rest for 4 hours, craft a tent, rest for another 3;
# there is no space between 5 and -rest (line above);
# spaces do not matter for flags and are stripped away
# unless there is an escape character before / after
'-rest 4 '
# you can pass empty flags,
# their presence is indicated with an empty string
'--debug '
# im bad at coming up with examples
'-craft spear '
# especially when they involve games
'-target rabbit '
# time to sleep now
'-rest 3'
)
args = flagopt.snip(flags, command)
moves = args.getall('-move')
print(moves)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
flagopt-0.0.0.tar.gz
(3.8 kB
view details)
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 flagopt-0.0.0.tar.gz.
File metadata
- Download URL: flagopt-0.0.0.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
275daf9e13c6fa2169c695b6c5a8ea8fc4b46335731911da921255f5caacc84a
|
|
| MD5 |
7d062d91542fe993938381e761e9f126
|
|
| BLAKE2b-256 |
6e760d8fcf86333c20fbb8cae122899516d94912c0b8bfeec98c4d0ed0444ec9
|
File details
Details for the file flagopt-0.0.0-py3-none-any.whl.
File metadata
- Download URL: flagopt-0.0.0-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5d8e385e03d573fc1bdd6c8c98baabdeed6ced5233dfc13d3f07a8634ce7903
|
|
| MD5 |
f57a6b8957c9b317eddc11f9f7dc8de5
|
|
| BLAKE2b-256 |
a4078e91a8e60f545ca9e258d00386762ad5e0fd2ccf28df2c84f5deef62f528
|