2025-08-09 15:14:44 +09:00
|
|
|
/*!
|
2025-09-20 09:11:52 +09:00
|
|
|
Minimal CLI entry point for Nyash.
|
|
|
|
|
Delegates to the library crate (`nyash_rust`) for all functionality.
|
|
|
|
|
*/
|
2025-08-19 05:43:37 +09:00
|
|
|
|
2025-08-19 05:36:01 +09:00
|
|
|
use nyash_rust::cli::CliConfig;
|
2025-09-03 05:04:56 +09:00
|
|
|
use nyash_rust::config::env as env_config;
|
2025-09-20 09:11:52 +09:00
|
|
|
use nyash_rust::runner::NyashRunner;
|
2025-08-09 15:14:44 +09:00
|
|
|
|
2025-08-14 13:16:12 +00:00
|
|
|
/// Thin entry point - delegates to CLI parsing and runner execution
|
|
|
|
|
fn main() {
|
2025-11-17 19:53:44 +09:00
|
|
|
// Optional: enable backtrace on stack overflow for deep debug runs.
|
|
|
|
|
// Guarded by env to keep default behavior unchanged.
|
2025-11-21 06:25:17 +09:00
|
|
|
if std::env::var("NYASH_DEBUG_STACK_OVERFLOW").ok().as_deref() == Some("1") {
|
2025-11-17 19:53:44 +09:00
|
|
|
unsafe {
|
|
|
|
|
let _ = backtrace_on_stack_overflow::enable();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-04 20:46:43 +09:00
|
|
|
// 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();
|
2025-11-09 23:40:36 +09:00
|
|
|
let route = nyash_rust::config::env::verify_primary_is_hakovm();
|
2025-11-06 15:41:52 +09:00
|
|
|
// Force flag may allow hv1-inline without route
|
|
|
|
|
let force_hv1_flag = nyash_rust::config::env::env_bool("HAKO_VERIFY_V1_FORCE_HAKOVM");
|
|
|
|
|
if has_json && (route || force_hv1_flag) {
|
2025-11-04 20:46:43 +09:00
|
|
|
let json = std::env::var("NYASH_VERIFY_JSON").unwrap_or_default();
|
2025-11-06 15:41:52 +09:00
|
|
|
// Option A: force hv1 inline (dev) — bypass parser entirely
|
|
|
|
|
if force_hv1_flag {
|
|
|
|
|
let rc = nyash_rust::runner::hv1_inline::run_json_v1_inline(&json);
|
|
|
|
|
println!("{}", rc);
|
|
|
|
|
std::process::exit(rc);
|
|
|
|
|
}
|
2025-11-04 20:46:43 +09:00
|
|
|
// 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);
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-03 05:04:56 +09:00
|
|
|
// Bootstrap env overrides from nyash.toml [env] early (管理棟)
|
|
|
|
|
env_config::bootstrap_from_toml_env();
|
2025-08-14 13:16:12 +00:00
|
|
|
// Parse command-line arguments
|
|
|
|
|
let config = CliConfig::parse();
|
2025-11-02 17:50:06 +09:00
|
|
|
// 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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-08-14 13:16:12 +00:00
|
|
|
// Create and run the execution coordinator
|
|
|
|
|
let runner = NyashRunner::new(config);
|
|
|
|
|
runner.run();
|
2025-08-14 07:19:23 +09:00
|
|
|
}
|
|
|
|
|
|
2025-08-09 15:14:44 +09:00
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
|
|
|
|
use super::*;
|
2025-09-20 09:11:52 +09:00
|
|
|
use nyash_rust::box_trait::{BoxCore, NyashBox, StringBox};
|
2025-09-17 07:43:07 +09:00
|
|
|
|
2025-08-09 15:14:44 +09:00
|
|
|
#[test]
|
|
|
|
|
fn test_main_functionality() {
|
2025-09-20 09:11:52 +09:00
|
|
|
// Smoke: library module path wiring works
|
2025-08-14 13:16:12 +00:00
|
|
|
let string_box = StringBox::new("test".to_string());
|
2025-08-09 15:14:44 +09:00
|
|
|
assert_eq!(string_box.to_string_box().value, "test");
|
2025-09-20 09:11:52 +09:00
|
|
|
let _ = (); // CLI wiring exists via nyash_rust::cli
|
2025-08-09 15:14:44 +09:00
|
|
|
}
|
|
|
|
|
}
|