Skip to content

feat: add clgraph CLI with analyze, diff, and mcp commands#56

Merged
mingjerli merged 3 commits intomainfrom
feat/cli-commands
Apr 12, 2026
Merged

feat: add clgraph CLI with analyze, diff, and mcp commands#56
mingjerli merged 3 commits intomainfrom
feat/cli-commands

Conversation

@mingjerli
Copy link
Copy Markdown
Owner

@mingjerli mingjerli commented Apr 12, 2026

Summary

  • Adds a Typer-based clgraph CLI with three subcommands: analyze, diff, and mcp
  • Each command wraps existing Pipeline methods — no new library logic
  • Supports --format table (Rich), --format json, and --format dot output modes

Details

File Change
src/clgraph/cli.py New — Typer app (~300 lines)
tests/test_cli.py New — 21 tests covering all commands, formats, and error paths
pyproject.toml Added typer + rich deps, [project.scripts] entry point
uv.lock Updated lockfile

Post-review fixes (cd96f4a)

  • Format validation: Replaced free-form str format params with AnalyzeFormat/DiffFormat enums — Typer now rejects invalid values (e.g. --format xml) at parse time
  • MCP ImportError test: Added test that patches clgraph.mcp to verify graceful error when fastmcp is not installed
  • Diff single-file test: Added test exercising from_sql_string path through diff command
  • Invalid format tests: Added tests for both analyze and diff rejecting unsupported formats

Test plan

  • All 21 new CLI tests pass
  • All 1,339 existing tests pass (41 skipped — pre-existing)
  • clgraph --help shows all three commands
  • clgraph analyze works with directories, single SQL files, and JSON pipeline files
  • clgraph diff detects added/removed/modified columns
  • Error paths (nonexistent paths, unsupported file types, invalid formats) return non-zero exit codes
  • MCP command gracefully handles missing fastmcp dependency

🤖 Generated with Claude Code

Adds a Typer-based CLI so users can interact with lineage from the
terminal without writing Python. Three subcommands wrap existing
Pipeline methods:

- clgraph analyze: parse SQL and display table/column/edge summary
- clgraph diff: compare lineage between two pipeline versions
- clgraph mcp: start MCP server for LLM integration

Supports --format table (Rich), json, and dot output modes.
- Replace free-form string format params with AnalyzeFormat/DiffFormat
  enums so Typer rejects invalid values like --format xml at parse time
- Add test for MCP ImportError path (missing fastmcp dependency)
- Add test for diff with single SQL files (from_sql_string path)
- Add tests for invalid format rejection on both analyze and diff
Rich/Typer inserts ANSI escape sequences around option names in help
output (e.g. --pipeline becomes \e[1;36m-\e[0m\e[1;36m-pipeline\e[0m),
causing string assertions to fail in CI where color is enabled.
Add _strip_ansi() helper and use it in help output tests.
@mingjerli mingjerli merged commit 62d9bc2 into main Apr 12, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant