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 hnsw-create --dimension N --m M --ef-construction N --distance-metric TYPE [--index-name NAME] Create HNSW index
77 hnsw-insert --input FILE [--name NAME] Insert vectors into HNSW index
78 hnsw-search --input FILE --k N [--name NAME] Search HNSW index
79 hnsw-stats [--name NAME] Show HNSW index statistics
80 hnsw-list List all HNSW indexes in database
81 hnsw-delete --index-name NAME Delete HNSW index and all vectors
82 hnsw-info [--index-name NAME] Show detailed HNSW index information
83 wal-checkpoint Trigger WAL checkpoint operation
84 wal-metrics Show WAL performance metrics and file sizes
85 wal-config Show WAL configuration settings
86 wal-stats Show detailed WAL statistics with derived metrics
87 snapshot-create --dir DIR Create database snapshot
88 snapshot-load --dir DIR Load database snapshot
89 debug-stats Show graph introspection data (JSON)
90 debug-dump --output PATH Export graph structure for debugging
91 debug-trace COMMAND [...] Enable trace logging for specific operation
92 pagerank --iterations N [--damping-factor F] PageRank centrality algorithm
93 betweenness Betweenness centrality algorithm
94 louvain [--max-iterations N] Louvain community detection algorithm
95
96Traversal Options:
97 --start Starting node ID for traversal
98 --max-depth Maximum depth for BFS (default: 3)
99 --depth Hop depth for k-hop (default: 2)
100 --direction Traversal direction: incoming|outgoing (default: outgoing)
101 --from Source node ID for shortest path
102 --to Target node ID for shortest path
103 --id Node ID for neighbors query
104
105Pattern Options:
106 --edge-type Edge type to match (required)
107 --start-label Start node label filter
108 --end-label End node label filter
109 --start-prop Start node property filter (format: key:value)
110 --end-prop End node property filter (format: key:value)
111
112HNSW Options:
113 --dimension Vector dimension (e.g., 768)
114 --m Number of bi-directional links (default: 16)
115 --ef-construction HNSW ef_construction parameter (default: 200)
116 --distance-metric Distance metric: cosine|euclidean|dot|manhattan
117 --index-name Index name for create (default: "default")
118 --name Index name for insert/search/stats (default: "default")
119 --k Number of nearest neighbors to return
120
121Examples:
122 sqlitegraph status
123 sqlitegraph --db /path/to/graph.db list
124 sqlitegraph bfs --start 123 --max-depth 3
125 sqlitegraph k-hop --start 123 --depth 2 --direction outgoing
126 sqlitegraph shortest-path --from 123 --to 456
127 sqlitegraph neighbors --id 123 --direction incoming
128 sqlitegraph bulk-insert-entities --input entities.json
129 sqlitegraph pattern-match --edge-type DEPENDS_ON --start-label "Function" --end-label "Module"
130 sqlitegraph pattern-match-fast --edge-type CALLS --direction outgoing
131 sqlitegraph hnsw-create --dimension 768 --m 16 --ef-construction 200 --distance-metric cosine
132 sqlitegraph migrate --dry-run
133"#
134 }
135}