Simplify BehaviorOnFailure
This commit is contained in:
parent
03d48dd735
commit
b153a01828
2 changed files with 17 additions and 14 deletions
|
|
@ -997,19 +997,18 @@ impl Build {
|
|||
match result {
|
||||
Ok(_) => true,
|
||||
Err(_) => {
|
||||
if let Some(failure_behavior) = command.failure_behavior {
|
||||
match failure_behavior {
|
||||
BehaviorOnFailure::DelayFail => {
|
||||
let mut failures = self.delayed_failures.borrow_mut();
|
||||
failures.push(format!("{command:?}"));
|
||||
}
|
||||
BehaviorOnFailure::Exit => {
|
||||
match command.failure_behavior {
|
||||
BehaviorOnFailure::DelayFail => {
|
||||
if self.fail_fast {
|
||||
exit!(1);
|
||||
}
|
||||
|
||||
let mut failures = self.delayed_failures.borrow_mut();
|
||||
failures.push(format!("{command:?}"));
|
||||
}
|
||||
BehaviorOnFailure::Exit => {
|
||||
exit!(1);
|
||||
}
|
||||
}
|
||||
if self.fail_fast {
|
||||
exit!(1);
|
||||
}
|
||||
false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,16 +25,16 @@ pub enum OutputMode {
|
|||
#[derive(Debug)]
|
||||
pub struct BootstrapCommand<'a> {
|
||||
pub command: &'a mut Command,
|
||||
pub failure_behavior: Option<BehaviorOnFailure>,
|
||||
pub failure_behavior: BehaviorOnFailure,
|
||||
pub output_mode: OutputMode,
|
||||
}
|
||||
|
||||
impl<'a> BootstrapCommand<'a> {
|
||||
pub fn delay_failure(self) -> Self {
|
||||
Self { failure_behavior: Some(BehaviorOnFailure::DelayFail), ..self }
|
||||
Self { failure_behavior: BehaviorOnFailure::DelayFail, ..self }
|
||||
}
|
||||
pub fn fail_fast(self) -> Self {
|
||||
Self { failure_behavior: Some(BehaviorOnFailure::Exit), ..self }
|
||||
Self { failure_behavior: BehaviorOnFailure::Exit, ..self }
|
||||
}
|
||||
pub fn output_mode(self, output_mode: OutputMode) -> Self {
|
||||
Self { output_mode, ..self }
|
||||
|
|
@ -43,6 +43,10 @@ impl<'a> BootstrapCommand<'a> {
|
|||
|
||||
impl<'a> From<&'a mut Command> for BootstrapCommand<'a> {
|
||||
fn from(command: &'a mut Command) -> Self {
|
||||
Self { command, failure_behavior: None, output_mode: OutputMode::SuppressOnSuccess }
|
||||
Self {
|
||||
command,
|
||||
failure_behavior: BehaviorOnFailure::Exit,
|
||||
output_mode: OutputMode::SuppressOnSuccess,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue