This commit is contained in:
2024-07-19 06:08:17 +00:00
parent 9d29487513
commit 6f50873592
3 changed files with 34 additions and 8 deletions

View File

@@ -42,6 +42,16 @@ impl Config {
self.obj.get(&k)
}
pub fn get_bool<S: AsRef<str> + ?Sized>(&self, s: &S) -> Option<&bool> {
match self.get(s) {
Some(y) => match y {
Yaml::Boolean(i) => Some(i),
_ => None,
},
None => None,
}
}
pub fn get_str<S: AsRef<str> + ?Sized>(&self, s: &S) -> Option<&str> {
match self.get(s) {
Some(y) => match y {
@@ -98,4 +108,8 @@ impl Config {
pub fn restore_command(&self) -> Option<Vec<String>> {
self.get_str_vec("restore_command")
}
pub fn pause_at_exit(&self) -> bool {
self.get_bool("pause_at_exit").map(|s| s.to_owned()).unwrap_or(false)
}
}

View File

@@ -52,7 +52,7 @@ impl Main {
} else {
let e = Self::call(cml)?;
let ok = match &e {
ExitStatus::Exited(c) => *c != 0,
ExitStatus::Exited(c) => *c == 0,
_ => false,
};
if !ok {
@@ -87,7 +87,7 @@ impl Main {
} else {
let e = Self::call(cml)?;
let ok = match &e {
ExitStatus::Exited(c) => *c != 0,
ExitStatus::Exited(c) => *c == 0,
_ => false,
};
if !ok {
@@ -115,7 +115,7 @@ impl Main {
} else {
let e = Self::call(cml)?;
let ok = match &e {
ExitStatus::Exited(c) => *c != 0,
ExitStatus::Exited(c) => *c == 0,
_ => false,
};
if !ok {
@@ -130,7 +130,6 @@ impl Main {
}
fn main() -> ExitCode {
println!("Hello, world!");
let argv: Vec<String> = std::env::args().collect();
let mut opts = Options::new();
opts.optflag("h", "help", "Print help message.");
@@ -164,12 +163,15 @@ fn main() -> ExitCode {
return ExitCode::from(1);
}
let m = Main::new(cfg, result.opt_present("d"));
match m.run() {
Ok(_) => {}
let e = match m.run() {
Ok(_) => 0,
Err(e) => {
println!("{}", e);
return ExitCode::from(1);
1
}
};
if m._cfg.pause_at_exit() {
utils::enter_continue();
}
return ExitCode::from(0);
return ExitCode::from(e);
}

View File

@@ -1,4 +1,5 @@
use std::env;
use std::io::Read;
use std::io::Write;
use std::path::Path;
use std::path::PathBuf;
@@ -36,3 +37,12 @@ pub fn ask_continue() -> bool {
}
}
}
pub fn enter_continue() {
print!("Press enter to continue.");
std::io::stdout().flush().unwrap();
let mut f = [0u8; 1];
match std::io::stdin().read_exact(&mut f) {
_ => {}
}
}