Skip to main content

sqlitegraph_cli/
cli.rs

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