callable-cli

A wrapper for building click CLIs that retains callable functions


License
BSD-3-Clause
Install
pip install callable-cli==0.0.1

Documentation

Callable CLI

Run tests codecov

A wrapper around Click that allows you to write CLIs that are both callable and invokable from the command line.

The issue this package was created to resolve is that the functions used to create Click commands are no longer callable as functions once they have been decoarated. Instead, you need to convert your arguments to a list of command line arguments, and invoke the CLI.

# with just click
import click

@click.group()
def cli():
    pass

@click.command("foo")
@click.option("--bar")
def foo(bar):
    print(bar)

cli(["foo", "--bar", "baz"])  # just doing foo("baz") would raise an error

With callable_cli, you can easily created Click command line interfaces while retaining the programmatic invokability of the functions used to create those interfaces.

import callable_cli

@callable_cli.create_group()
def cli():
    pass

@callable_cli.create_command(cli, "foo", {
    "bar: {},
})
def foo(bar):
    print(bar)

foo("baz")  # no error!

# and this still works
cli(["foo", "--bar", "baz"])