use super::{CliError, Failure, Provider, ToolCx, WarningCode};
fn passes(failure: &Failure, provider: Option<Provider>) -> Option<String> {
match (failure, provider) {
(Failure::ScriptingPassing { number, .. }, Some(Provider::Utm)) => {
Some(format!("UTM failed an Apple event in passing ({number}), as it does while a VM boots"))
}
(Failure::VmnetNotEnabled { .. }, Some(Provider::VmwareDesktop)) => Some(
"VMware made the private network's host-only device but said it couldn't enable it, as Fusion on current macOS does; the device is there now"
.to_owned(),
),
_ => None,
}
}
pub(super) async fn once_more<F, Fut>(cx: &ToolCx<'_>, step: &str, mut up: F) -> Result<(), CliError<Failure>>
where
F: FnMut() -> Fut,
Fut: Future<Output = Result<(), CliError<Failure>>>,
{
let done = up().await;
let why = match &done {
Err(CliError::Failed { failure, .. }) => passes(failure, cx.provider),
_ => None,
};
let Some(why) = why else { return done };
(cx.warn)(WarningCode::Retrying, &format!("`vagrant {step}`: {why}; running it again"));
up().await
}