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] [--db memory|PATH] [--command status]
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  reindex-all [options]     Rebuild all indexes (syncore + sync graph)
69  reindex-syncore [options] Rebuild core database indexes only
70  reindex-sync-graph [options] Rebuild graph indexes and caches only
71
72Reindexing Options:
73  --progress                Show progress during reindexing
74  --no-validate             Skip index validation after rebuilding
75  --batch-size SIZE         Batch size for processing (default: 1000)
76
77Examples:
78  sqlitegraph status
79  sqlitegraph --db /path/to/graph.db list
80  sqlitegraph reindex-all --progress
81  sqlitegraph reindex-syncore --batch-size 500
82  sqlitegraph migrate --dry-run
83"#
84    }
85}