sqlitegraph_cli/
cli.rs

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  Create HNSW index
77  hnsw-insert --input FILE  Insert vectors into HNSW index
78  hnsw-search --input FILE --k N  Search HNSW index
79  hnsw-stats                Show HNSW index statistics
80  wal-checkpoint            Trigger WAL checkpoint operation
81  wal-metrics                Show WAL performance metrics and file sizes
82  wal-config                 Show WAL configuration settings
83  wal-stats                  Show detailed WAL statistics with derived metrics
84  snapshot-create --dir DIR  Create database snapshot
85  snapshot-load --dir DIR     Load database snapshot
86
87Traversal Options:
88  --start                   Starting node ID for traversal
89  --max-depth                Maximum depth for BFS (default: 3)
90  --depth                    Hop depth for k-hop (default: 2)
91  --direction               Traversal direction: incoming|outgoing (default: outgoing)
92  --from                     Source node ID for shortest path
93  --to                       Target node ID for shortest path
94  --id                       Node ID for neighbors query
95
96Pattern Options:
97  --edge-type                Edge type to match (required)
98  --start-label              Start node label filter
99  --end-label                End node label filter
100  --start-prop               Start node property filter (format: key:value)
101  --end-prop                 End node property filter (format: key:value)
102
103HNSW Options:
104  --dimension               Vector dimension (e.g., 768)
105  --m                       Number of bi-directional links (default: 16)
106  --ef-construction         HNSW ef_construction parameter (default: 200)
107  --distance-metric         Distance metric: cosine|euclidean|dot|manhattan
108  --k                       Number of nearest neighbors to return
109
110Examples:
111  sqlitegraph status
112  sqlitegraph --db /path/to/graph.db list
113  sqlitegraph bfs --start 123 --max-depth 3
114  sqlitegraph k-hop --start 123 --depth 2 --direction outgoing
115  sqlitegraph shortest-path --from 123 --to 456
116  sqlitegraph neighbors --id 123 --direction incoming
117  sqlitegraph bulk-insert-entities --input entities.json
118  sqlitegraph pattern-match --edge-type DEPENDS_ON --start-label "Function" --end-label "Module"
119  sqlitegraph pattern-match-fast --edge-type CALLS --direction outgoing
120  sqlitegraph hnsw-create --dimension 768 --m 16 --ef-construction 200 --distance-metric cosine
121  sqlitegraph migrate --dry-run
122"#
123    }
124}