datajoely / click-tree-viz

Visualise CLI option tree generated using the Click library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Click CLI tree visualiser

CI

About this project

Click is a wonderful library for creating command line interfaces in Python. As projects become more complex, tech debt in the form of CLI inconsistency can emerge.

This library provides maintainers of Click CLI interfaces with the ability to document and visualise the decision tree configured in several formats such as JSON, GraphViz and even a pretty printed rich tree in the terminal.

Usage

from click_tree_viz import ClickTreeViz
import battleship # A Click object in your project

ClickTreeViz(battleship.cli).print()

This will print the following to the console:

CLI
├── mine
│   ├── remove
│   │   ├── [argument] x
│   │   └── [argument] y
│   └── set
│       ├── [argument] x
│       ├── [argument] y
│       ├── [option] --drifting
│       └── [option] --moored
└── ship
    ├── move
...

Render targets available:

Method Description
print() A simple visualisation in the terminal (demonstrated above).
to_dict() Returns a nested Python dictionary:
to_json() Returns a JSON string identical to the Python dictionary.
to_graph_viz() Returns a dot language as a Python string which can be rendered elsewhere:
rich_print() Utilises the rich library to print a visually appealing tree to the terminal:

About

Visualise CLI option tree generated using the Click library

License:MIT License


Languages

Language:Python 99.1%Language:Makefile 0.9%