Skip to main content

sqlitegraph_cli/
cli.rs

1use clap::{Parser, Subcommand, ValueEnum};
2use std::path::PathBuf;
3
4#[derive(Clone, Debug, ValueEnum)]
5pub enum BackendType {
6    Sqlite,
7    #[cfg(feature = "native-v3")]
8    V3,
9}
10
11impl Default for BackendType {
12    fn default() -> Self {
13        Self::Sqlite
14    }
15}
16
17#[derive(Parser)]
18#[command(name = "sqlitegraph")]
19#[command(about = "SQLiteGraph CLI - Graph database query tool")]
20#[command(version)]
21pub struct Cli {
22    /// Database file path
23    #[arg(short, long, default_value = "graph.db")]
24    pub db: PathBuf,
25
26    /// Backend type
27    #[arg(short, long, value_enum, default_value = "sqlite")]
28    pub backend: BackendType,
29
30    /// Allow write operations (default is read-only)
31    #[arg(long, global = true)]
32    pub write: bool,
33
34    #[command(subcommand)]
35    pub command: Commands,
36}
37
38#[derive(Subcommand)]
39pub enum Commands {
40    /// Query using Cypher-like syntax (read-only)
41    Query {
42        /// Cypher-like query (e.g., "MATCH (n:User) RETURN n.name")
43        query: String,
44    },
45
46    /// Show database status
47    Status,
48
49    /// List all nodes
50    List {
51        /// Filter by kind
52        #[arg(short, long)]
53        kind: Option<String>,
54    },
55
56    /// Breadth-first search
57    Bfs {
58        #[arg(short, long)]
59        start: i64,
60        #[arg(short, long, default_value = "3")]
61        depth: u32,
62    },
63
64    /// Shortest path
65    Path {
66        #[arg(short, long)]
67        from: i64,
68        #[arg(short, long)]
69        to: i64,
70    },
71
72    /// Get neighbors
73    Neighbors {
74        #[arg(short, long)]
75        id: i64,
76        #[arg(short, long, default_value = "outgoing")]
77        direction: Direction,
78    },
79
80    /// Run graph algorithm
81    Algo {
82        #[command(subcommand)]
83        command: AlgoCommands,
84    },
85
86    /// Export graph to file (requires --write)
87    Export {
88        #[arg(short, long)]
89        output: PathBuf,
90    },
91
92    /// Import graph from file (requires --write)
93    Import {
94        #[arg(short, long)]
95        input: PathBuf,
96    },
97
98    /// Insert node (requires --write)
99    Insert {
100        #[arg(short, long)]
101        kind: String,
102        #[arg(short, long)]
103        name: String,
104        #[arg(short, long)]
105        data: Option<String>,
106    },
107}
108
109#[derive(Subcommand)]
110pub enum AlgoCommands {
111    /// PageRank centrality
112    Pagerank {
113        #[arg(short, long, default_value = "100")]
114        iterations: usize,
115    },
116    /// Betweenness centrality
117    Betweenness,
118    /// Connected components
119    Components,
120    /// Topological sort
121    Topo,
122}
123
124#[derive(Clone, Debug, ValueEnum)]
125pub enum Direction {
126    Incoming,
127    Outgoing,
128    Both,
129}