Skip to content

Platitudes

The easiest way to create CLI applications.

Platitudes instances collect several CLI commands under a single application. They can then be accessed by calling them using the original function name.

Parameters:

Name Type Description Default
description str | None

The description that will be shown when we run the help for the whole application.

None

__call__

__call__(arguments: list[str] | None = None) -> None

Runs the CLI program.

By default we run with the arguments passed to the CLI, that is, sys.argv, and this is what you want 99% of the time. You can however pass all the commands as a list of strings, this is the mechanims used internally for testing the code.

Parameters:

Name Type Description Default
arguments list[str] | None

List of strings passed for the CLI parsing. Defaults to using sys.argv.

None

command

command(config_file: str | None = None) -> Callable

Add a function to the app.

The function will be accessible from the CLI using the original's function name. It is most often used as a decorator. The decorated function is not modified in any way and therefore can be used normally within your program. This is useful when we want to build CLI out of code that we would like to reuse for building a library.

Example
import platitudes as pl

app = pl.Platitudes(description="Say hello and goodbye")

@app.command()
def hello(name: str):
    print(f"Hello {name}")


@app.command()
def goodbye(name: str):
    print(f"Goodbye {name}")