sidestepper: dont start and end with padding "\n"s

also actually error out if we mess up with std::process::exit
This commit is contained in:
Mark Joshwel 2025-01-22 01:09:26 +08:00
parent c235c63194
commit 500b6067b2

View file

@ -19,6 +19,7 @@ use std::error::Error;
use std::fs::metadata; use std::fs::metadata;
use std::io::Write; use std::io::Write;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::process::exit;
use std::time::{Duration, SystemTime}; use std::time::{Duration, SystemTime};
use std::{env, fs, io, path}; use std::{env, fs, io, path};
@ -196,12 +197,12 @@ fn format_elapsed_time(secs: f64) -> String {
} }
fn main() { fn main() {
eprintln!("\nsota staircase SideStepper v5 (i3/a5)"); eprintln!("sota staircase SideStepper v5 (i3/a5)");
let behaviour = { let behaviour = {
let behaviour = cli_get_behaviour(); let behaviour = cli_get_behaviour();
// huh. pattern matching consumes the variable, so we ref (&) it. damn. // huh. pattern matching consumes the variable, so we ref (&) it. damn.
if let Err(e) = &behaviour { if let Err(e) = &behaviour {
eprintln!("critical error: {}\n", e); eprintln!("critical error: {}", e);
std::process::exit(1); std::process::exit(1);
} }
behaviour.unwrap() behaviour.unwrap()
@ -217,12 +218,10 @@ fn main() {
format!( format!(
"{} ({})", "{} ({})",
behaviour.repo_sotaignore_path.to_string_lossy(), behaviour.repo_sotaignore_path.to_string_lossy(),
{ match behaviour.repo_sotaignore_path.try_exists() {
if behaviour.repo_sotaignore_path.try_exists().unwrap_or(false) { Ok(true) => "exists",
"exists" Ok(false) => "non-existent",
} else { Err(_) => "unknown",
"non-existent"
}
} }
) )
} }
@ -266,12 +265,13 @@ fn main() {
eprintln!("skipped") eprintln!("skipped")
} }
Err(e) => { Err(e) => {
eprintln!("error ({})", e) eprintln!("error: ({})", e);
exit(2)
} }
} }
eprintln!( eprintln!(
"\n--- done! took {} ″~ ☆*: .。. o(≧▽≦)o .。.:*☆ ---\n", "\n--- done! took {} ″~ ☆*: .。. o(≧▽≦)o .。.:*☆ ---",
format_elapsed_time(all.elapsed().unwrap_or(zero_duration).as_secs_f64()) format_elapsed_time(all.elapsed().unwrap_or(zero_duration).as_secs_f64())
); );
} }