Skip to content

Commit

Permalink
properly return the exit code
Browse files Browse the repository at this point in the history
  • Loading branch information
esamattis committed Nov 29, 2024
1 parent 2431044 commit de6228d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
3 changes: 3 additions & 0 deletions scripts/error.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

exit 44
26 changes: 10 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::io::Write;

const VERSION: &str = env!("CARGO_PKG_VERSION");

fn rt() -> Result<()> {
fn rt() -> Result<i32> {
let default = String::new();
let mut args: Vec<String> = env::args().collect();

Expand Down Expand Up @@ -82,12 +82,12 @@ fn rt() -> Result<()> {
for runner in runners {
println!("{}", runner.name());
}
return Ok(());
return Ok(0);
}

if arg == "--version" || arg == "-v" || arg == "-V" {
println!("{}", VERSION);
return Ok(());
return Ok(0);
}

if arg == "--zsh-complete" {
Expand All @@ -113,7 +113,7 @@ fn rt() -> Result<()> {
);
}

return Ok(());
return Ok(0);
}

let mut errors: Vec<anyhow::Error> = Vec::new();
Expand Down Expand Up @@ -148,13 +148,13 @@ fn rt() -> Result<()> {
bail!("Some runners failed to load");
}
} else {
run_task(&args[1..], &runners)?;
return run_task(&args[1..], &runners);
}

return Ok(());
return Ok(0);
}

fn run_task(args: &[String], runners: &Vec<Box<dyn Runner>>) -> Result<()> {
fn run_task(args: &[String], runners: &Vec<Box<dyn Runner>>) -> Result<i32> {
let matching_runners: Vec<&Box<dyn Runner>> = runners
.iter()
.filter(|runner| runner.tasks().contains(&args[0]))
Expand All @@ -179,8 +179,7 @@ fn run_task(args: &[String], runners: &Vec<Box<dyn Runner>>) -> Result<()> {
};

if let Some(runner) = selected_runner {
runner.run(&args[0], &args[1..])?;
return Ok(());
return runner.run(&args[0], &args[1..]);
}

bail!("Unknown task '{}'", args[0]);
Expand Down Expand Up @@ -217,11 +216,6 @@ fn print_anyhow_error(e: &anyhow::Error) {
}
}

fn main() {
let res = rt();

if let Err(e) = res {
print_anyhow_error(&e);
process::exit(1)
}
fn main() -> Result<()> {
process::exit(rt()?);
}

0 comments on commit de6228d

Please sign in to comment.