use anyhow instead of unwrap
This commit is contained in:
parent
2814e88011
commit
86a1dfae00
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -51,6 +51,12 @@ dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.89"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6"
|
||||
|
||||
[[package]]
|
||||
name = "arrayref"
|
||||
version = "0.3.9"
|
||||
@ -441,6 +447,7 @@ dependencies = [
|
||||
name = "roblox_emulator_cli"
|
||||
version = "0.1.1"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
"roblox_emulator",
|
||||
]
|
||||
|
@ -8,5 +8,6 @@ description = "Use roblox_emulator from cli."
|
||||
authors = ["Rhys Lloyd <krakow20@gmail.com>"]
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.89"
|
||||
clap = { version = "4.5.18", features = ["derive"] }
|
||||
roblox_emulator = { version = "0.3.1", registry = "strafesnet" }
|
||||
|
15
src/main.rs
15
src/main.rs
@ -21,23 +21,22 @@ struct RunScriptSubcommand{
|
||||
input_file:PathBuf,
|
||||
}
|
||||
|
||||
fn main(){
|
||||
fn main()->anyhow::Result<()>{
|
||||
let cli=Cli::parse();
|
||||
match cli.command{
|
||||
Commands::RunScript(command)=>run_script(command.input_file),
|
||||
}
|
||||
}
|
||||
|
||||
fn run_script(
|
||||
input_file:PathBuf,
|
||||
){//->Result<(),roblox_emulator::runner::Error>{
|
||||
fn run_script(input_file:PathBuf)->anyhow::Result<()>{
|
||||
let source={
|
||||
let mut source=String::new();
|
||||
std::fs::File::open(input_file).unwrap().read_to_string(&mut source).unwrap();
|
||||
std::fs::File::open(input_file)?.read_to_string(&mut source)?;
|
||||
source
|
||||
};
|
||||
let (mut context,script,services)=roblox_emulator::context::Context::script_singleton(source);
|
||||
let runner=roblox_emulator::runner::Runner::new().unwrap();
|
||||
let runnable=runner.runnable_context(&mut context,&services).unwrap();
|
||||
runnable.run_script(script).unwrap();
|
||||
let runner=roblox_emulator::runner::Runner::new()?;
|
||||
let runnable=runner.runnable_context(&mut context,&services)?;
|
||||
runnable.run_script(script)?;
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user