Create CLIs using parser combinators and type hints
Project description
genbu
Genbu is a library for creating command-line interfaces using shell parser combinators and type hints.
Install
pip install genbu
Infer a parameter parser from type hints
import typing as t
from genbu.infer import infer_parser
parse = infer_parser(t.Optional[int])
assert parse(["5"]) == 5
assert parse(["-11"]) == -11
assert parse([""]) is None
assert parse(["None"]) is None
try:
parse(["12.13"])
except ValueError:
print("not an Optional[int]")
parse_tuple = infer_parser(tuple[float, ...])
assert parse_tuple(["1.5"]) == (1.5,)
assert parse_tuple(["0.0", "4.2", "-1"]) == (0.0, 4.2, -1.0)
assert parse_tuple([]) == ()
try:
parse(["Hello, world!"])
except ValueError:
print("not a tuple[float, ...]")
License
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
genbu-0.1.tar.gz
(19.0 kB
view details)
Built Distribution
genbu-0.1-py3-none-any.whl
(22.7 kB
view details)
File details
Details for the file genbu-0.1.tar.gz
.
File metadata
- Download URL: genbu-0.1.tar.gz
- Upload date:
- Size: 19.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
c401a3c2d7365e398a8f879af6569dbbf749951766cdde63987a348d9e2a5622
|
|
MD5 |
039b88a96a9a8e3359085badc572e7f7
|
|
BLAKE2b-256 |
9a14419b0cde01de2e1dc80c86542bb030502dd47bc6cd66711c26af26a21273
|
File details
Details for the file genbu-0.1-py3-none-any.whl
.
File metadata
- Download URL: genbu-0.1-py3-none-any.whl
- Upload date:
- Size: 22.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
7473e72cab93c13edd0193474111f08a5fd762dc7b1a9f7ea7143202fd265fdf
|
|
MD5 |
4ac20b6532667a3eecb7e540fbdd6e4b
|
|
BLAKE2b-256 |
c6eaace0ff61f53c7ff8fd39fa6a83e3ac56c12ad00b552b24acd040f270fced
|