1#[derive(Clone, Debug, PartialEq, Eq)]
2pub struct CommandLineConfig {
3 pub backend: String,
4 pub database: String,
5 pub command: String,
6 pub command_args: Vec<String>,
7}
8
9impl CommandLineConfig {
10 pub fn from_args(args: &[&str]) -> Result<Self, String> {
11 let mut backend = String::from("sqlite");
12 let mut database = String::from("memory");
13 let mut command = String::from("status");
14 let mut command_args = Vec::new();
15 let mut command_set = false;
16 let mut iter = args.iter().skip(1);
17 while let Some(arg) = iter.next() {
18 if command_set {
19 command_args.push(arg.to_string());
20 continue;
21 }
22 match *arg {
23 "--backend" => {
24 backend = iter
25 .next()
26 .ok_or_else(|| "--backend requires a value".to_string())?
27 .to_string();
28 }
29 "--db" | "--database" => {
30 database = iter
31 .next()
32 .ok_or_else(|| "--db requires a value".to_string())?
33 .to_string();
34 }
35 "--command" => {
36 command = iter
37 .next()
38 .ok_or_else(|| "--command requires a value".to_string())?
39 .to_string();
40 command_set = true;
41 }
42 other if other.starts_with('-') => {
43 return Err(format!("unknown flag {other}"));
44 }
45 _ => {
46 command = arg.to_string();
47 command_set = true;
48 }
49 }
50 }
51 Ok(Self {
52 backend,
53 database,
54 command,
55 command_args,
56 })
57 }
58
59 pub fn help() -> &'static str {
60 r#"Usage: sqlitegraph [--backend sqlite|native] [--db memory|PATH] [command] [args]
61
62Commands:
63 status Show database status and statistics
64 list List all entities in the graph
65 migrate [--dry-run] Run pending schema migrations
66 dump-graph --output PATH Dump graph data to file
67 load-graph --input PATH Load graph data from file
68 bulk-insert-entities --input FILE Bulk insert entities from JSON
69 bulk-insert-edges --input FILE Bulk insert edges from JSON
70 bfs --start ID --max-depth N Breadth-first search traversal
71 k-hop --start ID --depth N [--direction incoming|outgoing] K-hop neighbor query
72 shortest-path --from ID --to ID Find shortest path between nodes
73 neighbors --id ID [--direction incoming|outgoing] Direct neighbor query
74 pattern-match --edge-type TYPE [--start-label LABEL] [--end-label LABEL] [--direction incoming|outgoing] [--start-prop KEY:VAL] [--end-prop KEY:VAL] Match triple patterns
75 pattern-match-fast --edge-type TYPE [--start-label LABEL] [--end-label LABEL] [--direction incoming|outgoing] [--start-prop KEY:VAL] [--end-prop KEY:VAL] Fast-path pattern match
76 forward-reachability --start ID Find all nodes reachable from start node
77 backward-reachability --target ID Find all nodes that can reach target node
78 can-reach --from ID --to ID Check if from node can reach to node
79 unreachable-nodes --entry ID Find nodes unreachable from entry point
80 hnsw-create --dimension N --m M --ef-construction N --distance-metric TYPE [--index-name NAME] Create HNSW index
81 hnsw-insert --input FILE [--name NAME] Insert vectors into HNSW index
82 hnsw-search --input FILE --k N [--name NAME] Search HNSW index
83 hnsw-stats [--name NAME] Show HNSW index statistics
84 hnsw-list List all HNSW indexes in database
85 hnsw-delete --index-name NAME Delete HNSW index and all vectors
86 hnsw-info [--index-name NAME] Show detailed HNSW index information
87 wal-checkpoint Trigger WAL checkpoint operation
88 wal-metrics Show WAL performance metrics and file sizes
89 wal-config Show WAL configuration settings
90 wal-stats Show detailed WAL statistics with derived metrics
91 snapshot-create --dir DIR Create database snapshot
92 snapshot-load --dir DIR Load database snapshot
93 debug-stats Show graph introspection data (JSON)
94 debug-dump --output PATH Export graph structure for debugging
95 debug-trace COMMAND [...] Enable trace logging for specific operation
96 pagerank --iterations N [--damping-factor F] PageRank centrality algorithm
97 betweenness Betweenness centrality algorithm
98 louvain [--max-iterations N] Louvain community detection algorithm
99 enumerate-paths --start ID [--max-depth N] [--max-paths N] Enumerate execution paths with bounds
100 enumerate-paths-constrained --start ID [--enable-dominance] [--enable-cd] [--enable-loops] Path enumeration with pruning
101 critical-path Longest weighted path in DAG (bottleneck identification)
102 cycle-basis [--max-cycles N] [--max-cycle-length N] Minimal cycle basis for cycle explanation
103 wcc Weakly Connected Components (undirected connectivity)
104 scc Strongly Connected Components (Tarjan's algorithm)
105 transitive-closure [--max-depth N] [--max-sources N] [--max-pairs N] All-pairs reachability
106 transitive-reduction Remove redundant edges while preserving reachability
107 topological-sort Topological ordering of nodes in DAGs
108 structural-similarity --graph1 ID --graph2 ID Structural similarity using isomorphism and MCS
109 graph-diff --before PATH --after PATH Structural graph delta between two snapshots
110 validate-refactor --before PATH --after PATH Refactor validation with safety heuristics
111 taint-forward --sources-file FILE Forward taint propagation from sources to sinks
112 taint-backward --sink ID --sources-file FILE Backward taint propagation from sink to sources
113 sink-analysis --sources-file FILE --sinks-file FILE Full vulnerability detection (all sinks)
114 discover-sources-sinks Discover sources/sinks using metadata-based detectors
115 backward-slice --target ID Backward program slicing (what affects this node?)
116 forward-slice --source ID Forward program slicing (what does this affect?)
117 collapse-scc Collapse SCCs into supernodes for call graph analysis
118 min-cut --source ID --sink ID Minimum s-t edge cut for fault tolerance analysis
119 min-vertex-cut --source ID --sink ID Minimum vertex cut for critical node identification
120 dominators --entry ID Compute dominators and immediate dominator tree
121 post-dominators [--exit ID] Compute post-dominators (auto-detects exit if omitted)
122 control-dependence [--exit ID] Compute Control Dependence Graph
123 dominance-frontiers --entry ID Compute dominance frontiers for SSA phi-placement
124 natural-loops --entry ID Detect natural loops using back-edge dominance
125 happens-before --events-file FILE Event ordering analysis for concurrent traces
126 impact-radius --start ID [--max-distance N] Blast zone computation using bounded reachability
127 partition --k N [--max-size N] Size-bounded k-way graph partitioning
128 subgraph-isomorphism --pattern-file FILE Bounded subgraph isomorphism for pattern matching
129 graph-rewrite --rules-file FILE DPO-style graph rewriting for pattern transformation
130
131Traversal Options:
132 --start Starting node ID for traversal
133 --max-depth Maximum depth for BFS (default: 3)
134 --depth Hop depth for k-hop (default: 2)
135 --direction Traversal direction: incoming|outgoing (default: outgoing)
136 --from Source node ID for shortest path or can-reach
137 --to Target node ID for shortest path or can-reach
138 --id Node ID for neighbors query
139 --target Target node ID for backward reachability or backward-slice
140 --entry Entry node ID for unreachable nodes
141 --source Source node ID for forward-slice, min-cut, or min-vertex-cut
142 --sink Sink node ID for min-cut or min-vertex-cut
143
144Pattern Options:
145 --edge-type Edge type to match (required)
146 --start-label Start node label filter
147 --end-label End node label filter
148 --start-prop Start node property filter (format: key:value)
149 --end-prop End node property filter (format: key:value)
150
151HNSW Options:
152 --dimension Vector dimension (e.g., 768)
153 --m Number of bi-directional links (default: 16)
154 --ef-construction HNSW ef_construction parameter (default: 200)
155 --distance-metric Distance metric: cosine|euclidean|dot|manhattan
156 --index-name Index name for create (default: "default")
157 --name Index name for insert/search/stats (default: "default")
158 --k Number of nearest neighbors to return
159
160Examples:
161 sqlitegraph status
162 sqlitegraph --db /path/to/graph.db list
163 sqlitegraph bfs --start 123 --max-depth 3
164 sqlitegraph k-hop --start 123 --depth 2 --direction outgoing
165 sqlitegraph shortest-path --from 123 --to 456
166 sqlitegraph neighbors --id 123 --direction incoming
167 sqlitegraph forward-reachability --start 123
168 sqlitegraph backward-reachability --target 456
169 sqlitegraph can-reach --from 123 --to 456
170 sqlitegraph unreachable-nodes --entry 1
171 sqlitegraph bulk-insert-entities --input entities.json
172 sqlitegraph pattern-match --edge-type DEPENDS_ON --start-label "Function" --end-label "Module"
173 sqlitegraph pattern-match-fast --edge-type CALLS --direction outgoing
174 sqlitegraph hnsw-create --dimension 768 --m 16 --ef-construction 200 --distance-metric cosine
175 sqlitegraph migrate --dry-run
176 sqlitegraph backward-slice --target 456
177 sqlitegraph forward-slice --source 123
178 sqlitegraph collapse-scc
179 sqlitegraph min-cut --source 1 --sink 10
180 sqlitegraph min-vertex-cut --source 1 --sink 10
181"#
182 }
183}