Skip to content

geopozo/cli-tree

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.

import cli_tree
import typer

cli = typer.Typer(name="Your CLI")


@cli.callback()
def _cb(help_tree=cli_tree.help_tree_option):
    pass

Click

from cli_tree import AppTree

tree = 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

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages