Skip to content

Repository files navigation

cli-tree

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.

Typer

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):
pass

Click

fromcli_treeimportAppTreetree=AppTree.from_app_or_command(my_click_or_typer_object)
print(tree.to_json())
print(tree.to_ascii())

Bonus: Rich Development

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.

About

A helper package to print typer trees.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages