scripts.diagram-tools

Reference › scripts › diagram-tools

A global command-line entry point for the orchestrata-tools diagram subcommands, usable from any directory. main calls find_project_root to locate the nearest project containing a pyproject.toml; if there is none it prints an error and exits 1. Otherwise it runs orchestrata-tools with all of its own arguments, using the project root as the working directory, and returns that command's exit code.

At a glance

Source scripts/diagram-tools.py
Lines of code 49
Classes 0
Functions 2
Imports (internal) none
Imported by none
Tests that import it none

Class diagram

No classes; see Functions.

Dependency diagram

No internal imports and no importers.

API

Functions

Function Signature Summary
find_project_root find_project_root() -> Path | None
main main() -> None

Source

Permalink: https://gitlab.com/MSamy/orchestrata-ultimate-architecture/-/blob/a4cbc2bdf/scripts/diagram-tools.py

#!/usr/bin/env python3
"""Global CLI entry for orchestrata-tools diagram subcommands — usable from any directory.

Forwards all argv to the real ``orchestrata-tools`` console script (after
locating the nearest ancestor directory containing ``pyproject.toml``), so
its subcommand surface is whatever ``orchestrata-tools --help`` reports.

Usage:
    diagram-tools diagram --module orchestrata_ultimate.core   # Mermaid class/module diagram
    diagram-tools discover ...                                  # Discover codebase info
    diagram-tools query ...                                     # Query the AST

Note: earlier revisions of this docstring advertised ``diagram-to-code`` /
``diagram-from-code`` / ``diagram-roundtrip`` subcommands. Those never
existed as CLI subcommands of ``orchestrata-tools`` (only {discover,diagram,
query} do) — ``DiagramToCode`` is a Python class
(``orchestrata_tools.diagram.diagram_to_code``), not a CLI entry point. The
docstring was corrected to match the real CLI surface (2026-07-10).
"""

import sys
from pathlib import Path


def find_project_root() -> Path | None:
    current = Path.cwd().resolve()
    for parent in [current, *current.parents]:
        if (parent / "pyproject.toml").exists():
            return parent
    return None


def main() -> None:
    root = find_project_root()
    if root is None:
        print("diagram-tools: No project with pyproject.toml found", file=sys.stderr)
        sys.exit(1)

    import subprocess

    result = subprocess.run(
        ["orchestrata-tools", *sys.argv[1:]],
        cwd=str(root),
    )
    sys.exit(result.returncode)


if __name__ == "__main__":
    main()