diff --git a/src/app.rs b/src/app.rs index 6e9b5d5..2c19683 100644 --- a/src/app.rs +++ b/src/app.rs @@ -78,31 +78,26 @@ enum ShellCompletions { impl App { pub fn run(self) { match self.command { - Subcommand::New { name } => match create_project(&name) { - Err(e) => { + Subcommand::New { name } => { + if let Err(e) = create_project(&name) { eprintln!("Error creating project '{name}': {e}"); std::process::exit(1); } - _ => {} - }, - Subcommand::Init => match create_project(".") { - Err(e) => { + } + Subcommand::Init => { + if let Err(e) = create_project(".") { eprintln!("Error initializing project: {e}"); std::process::exit(1); } - _ => {} - }, + } Subcommand::Run { mode, args, force_recompile, } => { - match build(&mode, force_recompile) { - Err(e) => { - eprintln!("Error building project: {e}"); - std::process::exit(1); - } - _ => {} + if let Err(e) = build(&mode, force_recompile) { + eprintln!("Error building project: {e}"); + std::process::exit(1); }; if let Err(e) = run(&mode, args) { eprintln!("Error running project: {e}"); @@ -112,20 +107,18 @@ impl App { Subcommand::Build { mode, force_recompile, - } => match build(&mode, force_recompile) { - Err(e) => { + } => { + if let Err(e) = build(&mode, force_recompile) { eprintln!("Error building project: {e}"); std::process::exit(1); } - _ => {} - }, - Subcommand::Clean => match clean() { - Err(e) => { + } + Subcommand::Clean => { + if let Err(e) = clean() { eprintln!("Error cleaning project: {e}"); std::process::exit(1); } - _ => {} - }, + } Subcommand::Utils { command } => match command { UtilSubcommand::Completions { shell } => { let name = env!("CARGO_PKG_NAME"); @@ -158,13 +151,12 @@ impl App { } } }, - Subcommand::List => match list() { - Err(e) => { + Subcommand::List => { + if let Err(e) = list() { eprintln!("Error listing build profiles: {e}"); std::process::exit(1); } - _ => {} - }, + } } } } @@ -292,9 +284,14 @@ fn build(mode: &Option, force_recompile: bool) -> std::io::Result<()> { .arg("-o") .arg(format!("target/{}/{}", build_config.name, conf.name)); - let mut child = command.spawn()?; + let status = command.status()?; - child.wait()?; + if !status.success() { + return Err(std::io::Error::new( + std::io::ErrorKind::Other, + format!("compiler exited with status {status}"), + )); + } std::fs::write(format!("target/{}/.build_hash", build_config.name), hash)?; @@ -360,7 +357,7 @@ fn run(mode: &Option, args: Option>) -> std::io::Result<()> } fn clean() -> std::io::Result<()> { - if let None = get_config() { + if get_config().is_none() { return Err(std::io::Error::new( std::io::ErrorKind::NotFound, "no Pallet.toml found in local dir",