treeparse

group

Named container for commands, subgroups, shared arguments and options.

group

Groups organize commands hierarchically. They can carry inherited options/arguments.

from __future__ import annotations

from treeparse import cli, group, command, option

deploy = group(
    name="deploy",
    help="Deployment commands.",
    options=[
        option(
            flags=["--dry-run"],
            flag=True,
            inherit=True,
            help="Print actions without executing.",
        ),
    ],
)

deploy.commands.append(
    command(name="staging", help="Deploy to staging.", callback=deploy_staging),
)

app = cli(name="app")
app.subgroups.append(deploy)
  • inherit=True on an option makes it available (and passed to callbacks) for all child commands.
  • fold=True renders the group compactly as name [...] in help.
  • Use sort_key to control ordering in the tree.

On this page