Skip to main content

Create CLIs using parser combinators and type hints

Project description

genbu

GitHub Workflow Status PyPI PyPI - Python Version GitHub

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

MIT

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

genbu-0.1.tar.gz (19.0 kB view hashes)

Uploaded Source

Built Distribution

genbu-0.1-py3-none-any.whl (22.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page