Skip to main content

A CLI tool

Project description

Piou

CircleCI Latest PyPI version Latest conda-forge version

A CLI tool to build beautiful command-line interfaces with type validation.

It is as simple as

from piou import Cli, Option

cli = Cli(description='A CLI tool')


@cli.command(cmd='foo',
             help='Run foo command')
def foo_main(
    foo1: int = Option(..., help='Foo arguments'),
    foo2: str = Option(..., '-f', '--foo2', help='Foo2 arguments'),
    foo3: str = Option(None, '-g', '--foo3', help='Foo3 arguments'),
):
    pass

if __name__ == '__main__':
    cli.run()

The output will look like this:

example

You can also add sub-commands:

from piou import Cli, Option

cli = Cli(description='A CLI tool')

sub_cmd = cli.add_sub_parser(cmd='sub', description='A sub command')

sub_cmd.add_option(False, '-', '--dry-run', help='Run in dry run mode')


@sub_cmd.command(cmd='foo', help='Run baz command')
def baz_bar_main(**kwargs):
    pass


@sub_cmd.command(cmd='bar', help='Run toto command')
def toto_main(
        foo1: int = Option(..., help='Foo arguments'),
        foo2: str = Option(..., '-f', '--foo2', help='Foo2 arguments'),
):
    pass


if __name__ == '__main__':
    cli.run()

example

Here is a more complete example:

from piou import Cli, Option

cli = Cli(description='A CLI tool')

cli.add_option(None, '-q', '--quiet', help='Do not output any message')
cli.add_option(None, '--verbose', help='Increase verbosity')


@cli.command(cmd='foo',
             help='Run foo command')
def foo_main(
        quiet: bool,
        verbose: bool,
        foo1: int = Option(..., help='Foo arguments'),
        foo2: str = Option(..., '-f', '--foo2', help='Foo2 arguments'),
        foo3: str = Option(None, '-g', '--foo3', help='Foo3 arguments'),
):
    pass


@cli.command(cmd='bar', help='Run bar command')
def bar_main(**kwargs):
    pass


sub_cmd = cli.add_sub_parser(cmd='sub', description='A sub command')
sub_cmd.add_option(None, '--test', help='Test mode')


@sub_cmd.command(cmd='bar', help='Run baz command')
def baz_bar_main(
        **kwargs
):
    pass


@sub_cmd.command(cmd='toto', help='Run toto command')
def toto_main(
        test: bool,
        quiet: bool,
        verbose: bool,
        foo1: int = Option(..., help='Foo arguments'),
        foo2: str = Option(..., '-f', '--foo2', help='Foo2 arguments'),
):
    pass


if __name__ == '__main__':
    cli.run()

Try it by running python -m piou.test

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

piou-0.1.5.tar.gz (9.9 kB view hashes)

Uploaded Source

Built Distribution

piou-0.1.5-py3-none-any.whl (12.2 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