use std::path::PathBuf;
#[derive(clap::Parser)]
#[command(
name = "topodb",
about = "Direct-embedded CLI over a TopoDB database file"
)]
pub struct Cli {
#[arg(long, env = "TOPODB_DB")]
pub db: PathBuf,
#[arg(long, default_value = "shared")]
pub scope: String,
#[arg(long)]
pub pretty: bool,
#[command(subcommand)]
pub cmd: Command,
}
#[derive(clap::Subcommand)]
pub enum Command {
Info,
CreateMemory {
#[arg(long)]
content: String,
#[arg(long)]
props: Option<String>,
},
CreateEntity {
#[arg(long)]
name: String,
#[arg(long)]
props: Option<String>,
},
Link {
#[arg(long)]
from: String,
#[arg(long)]
to: String,
#[arg(long = "type")]
ty: String,
#[arg(long)]
props: Option<String>,
#[arg(long = "valid-from")]
valid_from: Option<i64>,
},
Get {
id: String,
},
Find {
#[arg(long)]
label: String,
#[arg(long)]
prop: String,
#[arg(long)]
value: String,
},
Search {
query: String,
#[arg(long, default_value_t = 10)]
k: usize,
},
Traverse {
seed: String,
#[arg(long = "max-hops", default_value_t = 2)]
max_hops: u8,
#[arg(long, value_enum, default_value_t = DirectionArg::Both)]
direction: DirectionArg,
#[arg(long = "edge-type")]
edge_type: Vec<String>,
},
Stats {
id: String,
},
Changes {
#[arg(long)]
since: u64,
},
Compact {
#[arg(long = "keep-from")]
keep_from: u64,
},
}
#[derive(clap::ValueEnum, Debug, Clone, Copy, Default)]
pub enum DirectionArg {
Out,
In,
#[default]
Both,
}
impl From<DirectionArg> for topodb::Direction {
fn from(d: DirectionArg) -> Self {
match d {
DirectionArg::Out => topodb::Direction::Out,
DirectionArg::In => topodb::Direction::In,
DirectionArg::Both => topodb::Direction::Both,
}
}
}