use clap::{Parser, Subcommand};
use eure::query::{TextFile, TextFileContent, build_runtime};
use eure::query_flow::DurabilityLevel;
use eure::report::format_error_reports;
use eure_mark::CheckEumdReferences;
use crate::util::{display_path, handle_query_error, read_input};
#[derive(Parser)]
pub struct Args {
#[command(subcommand)]
command: MarkCommands,
}
#[derive(Subcommand)]
enum MarkCommands {
Check(CheckArgs),
}
#[derive(Parser)]
struct CheckArgs {
file: Option<String>,
}
pub fn run(args: Args) {
match args.command {
MarkCommands::Check(check_args) => run_check(check_args),
}
}
fn run_check(args: CheckArgs) {
let contents = match read_input(args.file.as_deref()) {
Ok(c) => c,
Err(e) => {
eprintln!("{e}");
std::process::exit(1);
}
};
let runtime = build_runtime();
let path = display_path(args.file.as_deref());
let file: TextFile = TextFile::from_path(path.into());
runtime.resolve_asset(
file.clone(),
TextFileContent(contents),
DurabilityLevel::Static,
);
let reports = match runtime.query(CheckEumdReferences::new(file.clone())) {
Ok(result) => result,
Err(e) => handle_query_error(&runtime, e),
};
if reports.is_empty() {
println!("\x1b[1;32m✓\x1b[0m {} references OK", file);
} else {
eprintln!(
"{}",
format_error_reports(&runtime, &reports, true).expect("file content should be loaded")
);
std::process::exit(1);
}
}