Files
hakorune/src/main.rs

72 lines
2.9 KiB
Rust
Raw Normal View History

/*!
Minimal CLI entry point for Nyash.
Delegates to the library crate (`nyash_rust`) for all functionality.
*/
use nyash_rust::cli::CliConfig;
use nyash_rust::config::env as env_config;
use nyash_rust::runner::NyashRunner;
/// Thin entry point - delegates to CLI parsing and runner execution
fn main() {
// hv1 direct (primary): earliest possible check before any bootstrap/log init
// If NYASH_VERIFY_JSON is present and route is requested, execute and exit.
// This avoids plugin host/registry initialization and keeps output minimal.
let has_json = std::env::var("NYASH_VERIFY_JSON").is_ok();
let route = std::env::var("HAKO_ROUTE_HAKOVM").ok().as_deref() == Some("1")
|| std::env::var("HAKO_VERIFY_PRIMARY").ok().as_deref() == Some("hakovm");
if has_json && route {
let json = std::env::var("NYASH_VERIFY_JSON").unwrap_or_default();
// Minimal runner (no plugin init here); config parse is cheap and has no side effects.
let cfg = CliConfig::parse();
let runner = NyashRunner::new(cfg);
if std::env::var("NYASH_CLI_VERBOSE").ok().as_deref() == Some("1") {
eprintln!("[hv1-direct] early-exit (main)");
}
let rc = nyash_rust::runner::core_executor::run_json_v0(&runner, &json);
println!("{}", rc);
std::process::exit(rc);
}
// Bootstrap env overrides from nyash.toml [env] early (管理棟)
env_config::bootstrap_from_toml_env();
// Parse command-line arguments
let config = CliConfig::parse();
// Deprecation notice when invoked via legacy binary name
if let Ok(exe) = std::env::current_exe() {
if let Some(name) = exe.file_name().and_then(|s| s.to_str()) {
if name.eq_ignore_ascii_case("nyash") {
eprintln!("[deprecate] 'nyash' binary is deprecated. Please use 'hakorune'.");
}
}
}
// Legacy binary deprecation: prefer 'hakorune'
if let Ok(exe) = std::env::current_exe() {
if let Some(name) = exe.file_name().and_then(|s| s.to_str()) {
let allow_legacy = std::env::var("HAKO_ALLOW_NYASH").ok().as_deref() == Some("1")
|| std::env::var("NYASH_ALLOW_NYASH").ok().as_deref() == Some("1");
if name.eq_ignore_ascii_case("nyash") && !allow_legacy {
eprintln!("[deprecate] 'nyash' binary is deprecated. Please use 'hakorune'.");
std::process::exit(2);
}
}
}
// Create and run the execution coordinator
let runner = NyashRunner::new(config);
runner.run();
}
#[cfg(test)]
mod tests {
use super::*;
use nyash_rust::box_trait::{BoxCore, NyashBox, StringBox};
#[test]
fn test_main_functionality() {
// Smoke: library module path wiring works
let string_box = StringBox::new("test".to_string());
assert_eq!(string_box.to_string_box().value, "test");
let _ = (); // CLI wiring exists via nyash_rust::cli
}
}