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())]
|
#[command(version = build_info::version_formatted())]
|
||||||
pub struct Arguments {
|
pub struct Arguments {
|
||||||
/// Path to Lua entry point
|
/// Path to Lua entry point
|
||||||
#[arg(short, long)]
|
#[arg(short, long, default_value = "errornowatcher.lua")]
|
||||||
pub script: Option<PathBuf>,
|
pub script: PathBuf,
|
||||||
|
|
||||||
/// Code to execute after loading script
|
/// Code to execute after loading script
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
|
@ -29,7 +29,6 @@ use std::{
|
|||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
env,
|
env,
|
||||||
fs::{OpenOptions, read_to_string},
|
fs::{OpenOptions, read_to_string},
|
||||||
path::PathBuf,
|
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -52,16 +51,15 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
console_subscriber::init();
|
console_subscriber::init();
|
||||||
|
|
||||||
let args = Arguments::parse();
|
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 event_listeners = Arc::new(RwLock::new(HashMap::new()));
|
||||||
let lua = unsafe { Lua::unsafe_new() };
|
let lua = unsafe { Lua::unsafe_new() };
|
||||||
let globals = lua.globals();
|
let globals = lua.globals();
|
||||||
|
|
||||||
lua::register_globals(&lua, &globals, event_listeners.clone())?;
|
lua::register_globals(&lua, &globals, event_listeners.clone())?;
|
||||||
globals.set("SCRIPT_PATH", &*script_path)?;
|
globals.set("SCRIPT_PATH", &*args.script)?;
|
||||||
lua.load(
|
lua.load(
|
||||||
read_to_string(&script_path)
|
read_to_string(&args.script)
|
||||||
.with_context(|| format!("failed to read {}", script_path.display()))?,
|
.with_context(|| format!("failed to read {}", args.script.display()))?,
|
||||||
)
|
)
|
||||||
.exec()?;
|
.exec()?;
|
||||||
if let Some(code) = args.exec {
|
if let Some(code) = args.exec {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user