mod query;
mod read;
mod relationships;
mod statement;
use super::CommandError;
use clap::Subcommand;
use knowledge_base_crud::KnowledgeBase;
use knowledge_base_models::EntityId;
use std::num::NonZeroUsize;
use std::process::ExitCode;
#[derive(Debug, Subcommand)]
pub enum Command {
Read { id: EntityId },
Query {
#[arg(long = "filter", required = true)]
filters: Vec<String>,
#[arg(long, default_value = "100")]
limit: NonZeroUsize,
#[arg(long, default_value_t = 0)]
offset: usize,
},
Relationships {
id: EntityId,
#[arg(long, default_value = "100")]
limit: NonZeroUsize,
#[arg(long, default_value_t = 0)]
offset: usize,
},
Statement {
#[command(subcommand)]
command: statement::Command,
},
}
pub fn execute(command: Command, knowledge_base: &KnowledgeBase) -> Result<ExitCode, CommandError> {
match command {
Command::Read { id } => read::execute(knowledge_base, &id),
Command::Query { filters, limit, offset } => query::execute(knowledge_base, &filters, limit.get(), offset),
Command::Relationships { id, limit, offset } => relationships::execute(knowledge_base, &id, limit.get(), offset),
Command::Statement { command } => statement::execute(command, knowledge_base),
}
}