use std::path::PathBuf;
use clap::Subcommand;
use serde::Serialize;
#[derive(Subcommand, Debug)]
pub enum KgCommand {
Validate(ValidateArgs),
Init(InitArgs),
#[command(visible_alias = "sync")]
Fetch(FetchArgs),
Export(ExportArgs),
Import(ImportArgs),
Status(StatusArgs),
#[command(subcommand)]
Hook(HookCommand),
Commit(CommitArgs),
}
#[derive(clap::Parser, Debug)]
pub struct ValidateArgs {
#[arg(long, default_value = ".")]
pub repo: PathBuf,
#[arg(long)]
pub fix: bool,
#[arg(long)]
pub strict: bool,
#[arg(long, default_value = "text")]
pub format: OutputFormat,
#[arg(long)]
pub verbose: bool,
#[arg(long)]
pub quiet: bool,
#[arg(long)]
pub rules: Option<PathBuf>,
#[arg(long)]
pub no_rules: bool,
}
#[derive(clap::ValueEnum, Debug, Clone, Copy)]
pub enum OutputFormat {
Text,
Json,
Github,
}
impl std::fmt::Display for OutputFormat {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
OutputFormat::Text => write!(f, "text"),
OutputFormat::Json => write!(f, "json"),
OutputFormat::Github => write!(f, "github"),
}
}
}
#[derive(clap::Parser, Debug)]
pub struct InitArgs {
#[arg(long, default_value = ".")]
pub repo: PathBuf,
#[arg(long)]
pub ci: bool,
#[arg(long)]
pub add_hooks: bool,
}
#[derive(clap::Parser, Debug)]
pub struct FetchArgs {
pub remote: String,
#[arg(long, default_value = ".")]
pub repo: PathBuf,
#[arg(long)]
pub url: String,
#[arg(long = "ref", default_value = "main")]
pub git_ref: String,
#[arg(long, default_value = "local")]
pub namespace: String,
#[arg(long)]
pub pin: Option<String>,
#[arg(long)]
pub repin: bool,
}
#[derive(clap::Parser, Debug)]
pub struct ExportArgs {
pub output: PathBuf,
#[arg(long)]
pub db: PathBuf,
#[arg(long, default_value = "local")]
pub namespace: String,
}
#[derive(clap::Parser, Debug)]
pub struct ImportArgs {
pub source: PathBuf,
#[arg(long)]
pub db: PathBuf,
#[arg(long, default_value = "local")]
pub namespace: String,
#[arg(long, value_enum, default_value_t = ImportFormat::Archive)]
pub format: ImportFormat,
#[arg(long)]
pub verbose: bool,
}
#[derive(clap::ValueEnum, Debug, Clone, Copy, PartialEq, Eq)]
pub enum ImportFormat {
Archive,
Json,
Ndjson,
}
#[derive(clap::Parser, Debug)]
pub struct StatusArgs {
#[arg(long, default_value = ".")]
pub repo: PathBuf,
#[arg(long)]
pub db: PathBuf,
#[arg(long, default_value = "local")]
pub namespace: String,
}
#[derive(clap::Parser, Debug)]
pub struct CommitArgs {
pub changeset: PathBuf,
#[arg(long)]
pub rules: PathBuf,
#[arg(long, default_value = ".")]
pub repo: PathBuf,
#[arg(short = 'm', long = "message")]
pub message: String,
#[arg(long, default_value = "text")]
pub format: OutputFormat,
}
#[derive(Debug, Serialize)]
pub struct CommitReport {
pub commit_sha: String,
pub changeset_path: String,
pub ops: usize,
pub producer: String,
pub producer_batch: String,
}
#[derive(Subcommand, Debug)]
pub enum HookCommand {
Install {
#[arg(long, default_value = ".")]
repo: PathBuf,
},
Uninstall {
#[arg(long, default_value = ".")]
repo: PathBuf,
},
Status {
#[arg(long, default_value = ".")]
repo: PathBuf,
},
}
#[derive(Debug, Serialize)]
pub struct KgStatusReport {
pub db_hash: String,
pub ndjson_hash: String,
pub clean: bool,
}
#[derive(Debug, Serialize)]
pub struct ValidationReport {
pub rules: Vec<RuleResult>,
pub summary: ValidationSummary,
}
#[derive(Debug, Serialize)]
pub struct RuleResult {
pub id: String,
pub severity: &'static str,
pub passed: bool,
pub violations: Vec<Violation>,
}
#[derive(Debug, Serialize)]
pub struct Violation {
pub entity_id: Option<String>,
pub entity_name: Option<String>,
pub entity_kind: Option<String>,
pub rule_id: String,
pub severity: &'static str,
pub message: String,
pub fixable: bool,
}
#[derive(Debug, Serialize)]
pub struct ValidationSummary {
pub errors: usize,
pub warnings: usize,
pub info: usize,
pub entities: usize,
pub edges: usize,
pub passed: bool,
}
#[derive(Debug, Serialize)]
pub struct HookStatus {
pub symlink_exists: bool,
pub symlink_target: Option<String>,
pub target_valid: bool,
}