refactor(arguments): directly set default value for script in arguments

This commit is contained in:
Ryan 2025-03-13 17:31:19 -04:00
parent de5dbe600a
commit 477790db0e
Signed by: ErrorNoInternet
GPG Key ID: 2486BFB7B1E6A4A3
2 changed files with 5 additions and 7 deletions

View File

@ -7,8 +7,8 @@ use std::path::PathBuf;
#[command(version = build_info::version_formatted())]
pub struct Arguments {
/// Path to Lua entry point
#[arg(short, long)]
pub script: Option<PathBuf>,
#[arg(short, long, default_value = "errornowatcher.lua")]
pub script: PathBuf,
/// Code to execute after loading script
#[arg(short, long)]

View File

@ -29,7 +29,6 @@ use std::{
collections::HashMap,
env,
fs::{OpenOptions, read_to_string},
path::PathBuf,
sync::Arc,
};
@ -52,16 +51,15 @@ async fn main() -> anyhow::Result<()> {
console_subscriber::init();
let args = Arguments::parse();
let script_path = args.script.unwrap_or(PathBuf::from("errornowatcher.lua"));
let event_listeners = Arc::new(RwLock::new(HashMap::new()));
let lua = unsafe { Lua::unsafe_new() };
let globals = lua.globals();
lua::register_globals(&lua, &globals, event_listeners.clone())?;
globals.set("SCRIPT_PATH", &*script_path)?;
globals.set("SCRIPT_PATH", &*args.script)?;
lua.load(
read_to_string(&script_path)
.with_context(|| format!("failed to read {}", script_path.display()))?,
read_to_string(&args.script)
.with_context(|| format!("failed to read {}", args.script.display()))?,
)
.exec()?;
if let Some(code) = args.exec {