refactor(arguments): directly set default value for script in arguments
This commit is contained in:
parent
de5dbe600a
commit
477790db0e
@ -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)]
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user