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`] group for `#[command(flatten)]` composition.
8
9/// Help text for host/XDG `--db` no-op (English; agent-facing clap surface).
10pub 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";
11
12/// Flattenable no-op `--db` for host/XDG argument structs (GAP-SG-139).
13#[derive(Debug, Clone, Default, clap::Args)]
14pub struct DbNoopArgs {
15    /// Explicit database path. Accepted as a no-op for agent uniformity;
16    /// host/XDG surfaces do not open the graph database.
17    #[arg(long, value_name = "PATH", help = DB_NOOP_HELP)]
18    pub db: Option<String>,
19}
20
21impl DbNoopArgs {
22    /// Drop the value without using it (explicit no-op at the handler).
23    #[inline]
24    pub fn ignore(self) {
25        let _ = self.db;
26    }
27}
28
29#[cfg(test)]
30mod tests {
31    use super::*;
32    use clap::Parser;
33
34    #[derive(Debug, Parser)]
35    struct Probe {
36        #[command(flatten)]
37        db_noop: DbNoopArgs,
38    }
39
40    #[test]
41    fn db_noop_parses_long_flag() {
42        let p = Probe::try_parse_from(["probe", "--db", "/tmp/sentinel.sqlite"])
43            .expect("DbNoopArgs must accept --db");
44        assert_eq!(p.db_noop.db.as_deref(), Some("/tmp/sentinel.sqlite"));
45        p.db_noop.ignore();
46    }
47
48    #[test]
49    fn db_noop_optional() {
50        let p = Probe::try_parse_from(["probe"]).expect("DbNoopArgs must be optional");
51        assert!(p.db_noop.db.is_none());
52    }
53}