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 hashes)
Built Distribution
genbu-0.1-py3-none-any.whl
(22.7 kB
view hashes)