feat: Grundgerüst mit Konfiguration, SQLite-Schema und Selbsttest (M2.1)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
79
crates/nexus/src/main.rs
Normal file
79
crates/nexus/src/main.rs
Normal file
@ -0,0 +1,79 @@
|
||||
//! Nexus: AI Gateway für srv04.
|
||||
//!
|
||||
//! Stand M2.1: `version` und `selftest`. Der Server kommt mit M2.3.
|
||||
|
||||
mod selftest;
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::process::ExitCode;
|
||||
|
||||
const HILFE: &str = "\
|
||||
Nexus – AI Gateway für srv04
|
||||
|
||||
Aufruf:
|
||||
nexus version Version anzeigen
|
||||
nexus selftest [--config PFAD] Konfiguration, Datenverzeichnis und Datenbank prüfen
|
||||
nexus help Diese Hilfe
|
||||
|
||||
Die Konfiguration kann auch über die Umgebungsvariable NEXUS_CONFIG angegeben werden.
|
||||
";
|
||||
|
||||
fn main() -> ExitCode {
|
||||
let args: Vec<String> = std::env::args().skip(1).collect();
|
||||
match args.first().map(String::as_str) {
|
||||
Some("version") | Some("--version") => {
|
||||
println!("nexus {}", nexus_core::VERSION);
|
||||
ExitCode::SUCCESS
|
||||
}
|
||||
Some("selftest") => run_selftest(&args[1..]),
|
||||
Some("help") | Some("--help") | None => {
|
||||
print!("{HILFE}");
|
||||
ExitCode::SUCCESS
|
||||
}
|
||||
Some(other) => {
|
||||
eprintln!("Unbekannter Befehl: {other}\n");
|
||||
eprint!("{HILFE}");
|
||||
ExitCode::from(2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn run_selftest(args: &[String]) -> ExitCode {
|
||||
let config = match config_path(args) {
|
||||
Ok(path) => path,
|
||||
Err(message) => {
|
||||
eprintln!("{message}");
|
||||
return ExitCode::from(2);
|
||||
}
|
||||
};
|
||||
let checks = selftest::run(config.as_deref());
|
||||
let mut failed = 0;
|
||||
for c in &checks {
|
||||
match &c.result {
|
||||
Ok(detail) => println!("ok {}: {detail}", c.name),
|
||||
Err(detail) => {
|
||||
failed += 1;
|
||||
println!("FEHLER {}: {detail}", c.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
if failed == 0 {
|
||||
println!("Selbsttest bestanden ({} Prüfungen).", checks.len());
|
||||
ExitCode::SUCCESS
|
||||
} else {
|
||||
println!(
|
||||
"Selbsttest fehlgeschlagen ({failed} von {} Prüfungen).",
|
||||
checks.len()
|
||||
);
|
||||
ExitCode::FAILURE
|
||||
}
|
||||
}
|
||||
|
||||
/// Ermittelt den Konfigurationspfad: `--config`, sonst `NEXUS_CONFIG`.
|
||||
fn config_path(args: &[String]) -> Result<Option<PathBuf>, String> {
|
||||
match args {
|
||||
[] => Ok(std::env::var_os("NEXUS_CONFIG").map(PathBuf::from)),
|
||||
[flag, path] if flag == "--config" => Ok(Some(PathBuf::from(path))),
|
||||
_ => Err("Aufruf: nexus selftest [--config PFAD]".to_string()),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user