Note: Currently only supports typer (and therefore click, but manually).
cli-tree allows you to print out all the commands, subcommands, and help for your cli interface as a tree (json or ascii).
This allows for easy inspection and version tracking.
The following code snippet will add a universal --help-tree=ascii|json flag to
your cli.
importcli_treeimporttypercli=typer.Typer(name="Your CLI")
@cli.callback()def_cb(help_tree=cli_tree.help_tree_option):
passfromcli_treeimportAppTreetree=AppTree.from_app_or_command(my_click_or_typer_object)
print(tree.to_json())
print(tree.to_ascii())For developing rich output, I recommend writing a sample (so mock the output) and have it rendered automatically with
# Windows compatible:
watchexec -w FILENAME -r -c -- uv run FILENAME
# Linux:echo FILENAME | entr -rc uv run FILENAME
I run those commands in an embedded terminal in my text editor.