Skip to main content

sqlite_graphrag/
cli_db_noop.rs

1//! Shared no-op `--db` flag for host/XDG CLI surfaces (GAP-SG-139).
2//!
3//! Graph-scoped subcommands resolve storage via `--db`. Host/XDG surfaces
4//! (`config`, `slots`, `cache`, `completions`, `codex-models`) never open the
5//! graph database, but agents that append `--db` to every one-shot invocation
6//! must not receive clap exit 2. This module provides a single help string and
7//! an optional [`DbNoopArgs`](crate::cli_db_noop::DbNoopArgs) group for
8//! `#[command(flatten)]` composition.
9
10/// Help text for host/XDG `--db` no-op (English; agent-facing clap surface).
11pub const DB_NOOP_HELP: &str = "Explicit database path. Accepted as a no-op for agent uniformity; host/XDG surfaces do not open the graph database";
12
13/// Flattenable no-op `--db` for host/XDG argument structs (GAP-SG-139).
14#[derive(Debug, Clone, Default, clap::Args)]
15pub struct DbNoopArgs {
16    /// Explicit database path. Accepted as a no-op for agent uniformity;
17    /// host/XDG surfaces do not open the graph database.
18    #[arg(long, value_name = "PATH", help = DB_NOOP_HELP)]
19    pub db: Option<String>,
20}
21
22impl DbNoopArgs {
23    /// Drop the value without using it (explicit no-op at the handler).
24    #[inline]
25    pub fn ignore(self) {
26        let _ = self.db;
27    }
28}
29
30#[cfg(test)]
31mod tests {
32    use super::*;
33    use clap::Parser;
34
35    #[derive(Debug, Parser)]
36    struct Probe {
37        #[command(flatten)]
38        db_noop: DbNoopArgs,
39    }
40
41    #[test]
42    fn db_noop_parses_long_flag() {
43        let p = Probe::try_parse_from(["probe", "--db", "/tmp/sentinel.sqlite"])
44            .expect("DbNoopArgs must accept --db");
45        assert_eq!(p.db_noop.db.as_deref(), Some("/tmp/sentinel.sqlite"));
46        p.db_noop.ignore();
47    }
48
49    #[test]
50    fn db_noop_optional() {
51        let p = Probe::try_parse_from(["probe"]).expect("DbNoopArgs must be optional");
52        assert!(p.db_noop.db.is_none());
53    }
54}