Skip to content

graph & export

canontra graph <FILE> [--scope] [--calls] [--deps] [--cfg] [--dfg] [--json]
canontra export <FILE> [-f|--format sarif|dot] [-o|--output OUT_FILE] [-b|--base BASE_FILE] [-g|--graph calls|cfg|dfg]
  • graph: Prints the lexical scope tree, call graph, imports, Control Flow Graph (CFG), or SSA Data Flow Graph (DFG) for one source file. In human mode with no view flags, it prints the call graph; with --json, it outputs all five structures together.
  • export: Outputs machine-readable reports or graph files:
    • OASIS SARIF v2.1.0 (--format sarif, default): Compares FILE against --base (or git show HEAD:<FILE>) and outputs SARIF findings for GitHub Code Scanning and SonarQube.
    • Graphviz DOT (--format dot): Outputs the call graph, CFG, or DFG in DOT format for visualization tools.

Both sarif and dot modes accept - to read from standard input.

Flag Short Applies To Default Description
--scope - graph false Show lexical scope tree
--calls - graph false Show intra-module call graph
--deps - graph false Show resolved import dependencies
--cfg - graph false Show canonicalized Control Flow Graph
--dfg - graph false Show SSA Data Flow Graph
--json - graph false Output all five graph structures as JSON
--format -f export sarif Export format: sarif or dot
--output -o export stdout Write output to OUT_FILE instead of stdout
--base -b export git HEAD Baseline file to compare against for SARIF export
--graph -g export calls Graph type for DOT export: calls, cfg, or dfg

canontra graph <FILE> --json outputs:

{
"call_graph": { "...": "..." },
"scope_tree": { "...": "..." },
"dependency_graph": { "...": "..." },
"control_flow": [ ],
"data_flow": [ ]
}

Exit codes: 0 on success, 2 on invalid --format, 3 on parse error, 4 on missing input/base file or path traversal failure.

Terminal window
# Inspect CFG and DFG for a Python module
canontra graph src/pipeline.py --cfg --dfg
# Export OASIS SARIF v2.1.0 against a baseline file
canontra export src/service.ts --format sarif -b baseline/service.ts -o findings.sarif
# Export Control Flow Graph to Graphviz DOT
canontra export src/router.go --format dot -g cfg -o router_cfg.dot