cli
The root CLI object. Inherits from group.
cli
The entry point. Create with cli(...) and call .run().
from __future__ import annotations
from treeparse import cli, command
app = cli(
name="myapp",
help="Description shown at the top of the tree.",
max_width=120,
show_types=True,
show_defaults=True,
line_connect=False,
# theme=...,
)
app.run()cli is a group, so it accepts the same arguments, options, commands, subgroups, callback (for a root command), fold, sort_key.
Composing CLIs
A cli can be nested in another cli's subgroups, so standalone tools plug into a toolbox unchanged. A flat cli — one with a root callback and no commands or subgroups — acts as a single command at its position in the tree:
def annotate(name: str) -> None:
"""Open a new blank SVG for annotation."""
...
ink = cli(
name="ink",
help="Annotate figures.",
callback=annotate,
arguments=[argument(name="name", arg_type=str)],
)
toolbox = cli(name="toolbox", help="Creative toolbox.", subgroups=[ink])
# toolbox ink fig1 -> runs annotate("fig1")Its callback is signature-validated like any command, ancestor inherit=True options reach it, and --hv/-j show its docstring.
See group for inherited behavior.