chain
Compose multiple commands that execute sequentially.
chain
Chains let you define pipelines of commands that run in order. Parameters are merged.
from __future__ import annotations
from treeparse import cli, chain, command, argument, option
from treeparse.models.chain import chain as make_chain
def step1(input: str) -> None:
print("step1", input)
def step2(input: str, mode: str = "fast") -> None:
print("step2", input, mode)
c = make_chain(
name="pipeline",
help="Run step1 then step2.",
chained_commands=[
command(name="step1", callback=step1, arguments=[argument(name="input", arg_type=str)]),
command(
name="step2",
callback=step2,
arguments=[argument(name="input", arg_type=str)],
options=[option(flags=["--mode"], arg_type=str, default="fast")],
),
],
)
app = cli(name="app", commands=[c])The chain appears as a single top-level command. When invoked, each callback is called in sequence with its own subset of the (merged) arguments.