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        /// Use compact output format (single line, no pretty-print)
44        #[arg(long)]
45        compact: bool,
46    },
47
48    /// List all nodes
49    List {
50        /// Filter by kind
51        #[arg(short, long)]
52        kind: Option<String>,
53    },
54
55    /// Breadth-first search
56    Bfs {
57        #[arg(short, long)]
58        start: i64,
59        #[arg(short, long, default_value = "3")]
60        depth: u32,
61    },
62
63    /// Shortest path
64    Path {
65        #[arg(short, long)]
66        from: i64,
67        #[arg(short, long)]
68        to: i64,
69    },
70
71    /// Get neighbors
72    Neighbors {
73        #[arg(short, long)]
74        id: i64,
75        #[arg(short, long, default_value = "outgoing")]
76        direction: Direction,
77    },
78
79    /// Run graph algorithm
80    Algo {
81        #[command(subcommand)]
82        command: AlgoCommands,
83    },
84
85    /// Export graph to file (requires --write)
86    Export {
87        #[arg(short, long)]
88        output: PathBuf,
89    },
90
91    /// Import graph from file (requires --write)
92    Import {
93        #[arg(short, long)]
94        input: PathBuf,
95    },
96
97    /// Insert node (requires --write)
98    Insert {
99        #[arg(short, long)]
100        kind: String,
101        #[arg(short, long)]
102        name: String,
103        #[arg(short, long)]
104        data: Option<String>,
105    },
106}
107
108#[derive(Subcommand)]
109pub enum AlgoCommands {
110    /// PageRank centrality
111    Pagerank {
112        #[arg(short, long, default_value = "100")]
113        iterations: usize,
114    },
115    /// Betweenness centrality
116    Betweenness,
117    /// Connected components
118    Components,
119    /// Topological sort
120    Topo,
121}
122
123#[derive(Clone, Debug, ValueEnum)]
124pub enum Direction {
125    Incoming,
126    Outgoing,
127    Both,
128}