treeparse

command

A leaf command with callback, arguments and options.

command

A runnable leaf. Requires a callback.

from __future__ import annotations

from treeparse import command, argument, option


def build(input_path: str, output: str | None, force: bool) -> None:
    # implementation
    ...


cmd = command(
    name="build",
    help="Build the project.",
    callback=build,
    arguments=[argument(name="input_path", arg_type=str)],
    options=[
        option(flags=["--output", "-o"], arg_type=str),
        option(flags=["--force", "-f"], flag=True),
    ],
    sort_key=10,
)

Rules

  • Callback parameter names must exactly match argument.name / option dest names.
  • Types must be compatible with arg_type.
  • Every parameter in the callback signature must be covered by an argument or option (and vice versa for required ones).

See argument and option.

On this page