mirror of
https://github.com/TheM1Stery/izanami.git
synced 2025-04-20 00:41:11 +00:00
refactor: use match with cmp instead of bunch of if's
This commit is contained in:
parent
54912b7087
commit
2230c468e4
12
src/main.rs
12
src/main.rs
@ -1,14 +1,16 @@
|
|||||||
use std::{env::args_os, ffi::OsString, process::ExitCode};
|
use std::{cmp::Ordering, env::args_os, ffi::OsString, process::ExitCode};
|
||||||
|
|
||||||
use izanami::{run_file, run_prompt, RunError};
|
use izanami::{run_file, run_prompt, RunError};
|
||||||
|
|
||||||
fn main() -> ExitCode {
|
fn main() -> ExitCode {
|
||||||
let args: Vec<OsString> = args_os().collect();
|
let args: Vec<OsString> = args_os().collect();
|
||||||
|
|
||||||
if args.len() > 2 {
|
match args.len().cmp(&2) {
|
||||||
|
Ordering::Greater => {
|
||||||
println!("usage: izanami [script]");
|
println!("usage: izanami [script]");
|
||||||
return ExitCode::from(64);
|
return ExitCode::from(64);
|
||||||
} else if args.len() == 2 {
|
}
|
||||||
|
Ordering::Equal => {
|
||||||
let result = run_file(args[1].to_str().unwrap());
|
let result = run_file(args[1].to_str().unwrap());
|
||||||
|
|
||||||
if let Err(RunError::FileReadError(e)) = result {
|
if let Err(RunError::FileReadError(e)) = result {
|
||||||
@ -27,7 +29,8 @@ fn main() -> ExitCode {
|
|||||||
if let Err(RunError::ParseError) = result {
|
if let Err(RunError::ParseError) = result {
|
||||||
return ExitCode::from(75);
|
return ExitCode::from(75);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
Ordering::Less => {
|
||||||
let result = run_prompt();
|
let result = run_prompt();
|
||||||
|
|
||||||
if let Err(res) = result {
|
if let Err(res) = result {
|
||||||
@ -35,6 +38,7 @@ fn main() -> ExitCode {
|
|||||||
return ExitCode::from(1);
|
return ExitCode::from(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ExitCode::SUCCESS
|
ExitCode::SUCCESS
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user