diff --git a/src/cli/subcommand/install.rs b/src/cli/subcommand/install.rs index 0ee4232..510e9c6 100644 --- a/src/cli/subcommand/install.rs +++ b/src/cli/subcommand/install.rs @@ -80,13 +80,16 @@ impl CommandExecute for Install { match existing_receipt { Some(existing_receipt) => { if existing_receipt.planner.typetag_name() != chosen_planner.typetag_name() { - return Err(eyre!("Found existing plan in `{RECEIPT_LOCATION}` which used a different planner, try uninstalling the existing install")) + eprintln!("{}", format!("Found existing plan in `{RECEIPT_LOCATION}` which used a different planner, try uninstalling the existing install").red()); + return Ok(ExitCode::FAILURE) } if existing_receipt.planner.settings().map_err(|e| eyre!(e))? != chosen_planner.settings().map_err(|e| eyre!(e))? { - return Err(eyre!("Found existing plan in `{RECEIPT_LOCATION}` which used different planner settings, try uninstalling the existing install")) + eprintln!("{}", format!("Found existing plan in `{RECEIPT_LOCATION}` which used different planner settings, try uninstalling the existing install").red()); + return Ok(ExitCode::FAILURE) } if existing_receipt.actions.iter().all(|v| v.state == ActionState::Completed) { - return Err(eyre!("Found existing plan in `{RECEIPT_LOCATION}`, with the same settings, already completed, try uninstalling and reinstalling if Nix isn't working")) + eprintln!("{}", format!("Found existing plan in `{RECEIPT_LOCATION}`, with the same settings, already completed, try uninstalling and reinstalling if Nix isn't working").red()); + return Ok(ExitCode::FAILURE) } existing_receipt } , @@ -105,16 +108,35 @@ impl CommandExecute for Install { let builtin_planner = BuiltinPlanner::from_common_settings(settings) .await .map_err(|e| eyre::eyre!(e))?; - let res = builtin_planner.plan().await; - match res { - Ok(plan) => plan, - Err(e) => { - if let Some(expected) = e.expected() { - eprintln!("{}", expected.red()); - return Ok(ExitCode::FAILURE); + match existing_receipt { + Some(existing_receipt) => { + if existing_receipt.planner.typetag_name() != builtin_planner.typetag_name() { + eprintln!("{}", format!("Found existing plan in `{RECEIPT_LOCATION}` which used a different planner, try uninstalling the existing install").red()); + return Ok(ExitCode::FAILURE) } - return Err(e.into()) - } + if existing_receipt.planner.settings().map_err(|e| eyre!(e))? != builtin_planner.settings().map_err(|e| eyre!(e))? { + eprintln!("{}", format!("Found existing plan in `{RECEIPT_LOCATION}` which used different planner settings, try uninstalling the existing install").red()); + return Ok(ExitCode::FAILURE) + } + if existing_receipt.actions.iter().all(|v| v.state == ActionState::Completed) { + eprintln!("{}", format!("Found existing plan in `{RECEIPT_LOCATION}`, with the same settings, already completed, try uninstalling and reinstalling if Nix isn't working").red()); + return Ok(ExitCode::FAILURE) + } + existing_receipt + }, + None => { + let res = builtin_planner.plan().await; + match res { + Ok(plan) => plan, + Err(e) => { + if let Some(expected) = e.expected() { + eprintln!("{}", expected.red()); + return Ok(ExitCode::FAILURE); + } + return Err(e.into()) + } + } + }, } }, (Some(_), Some(_)) => return Err(eyre!("`--plan` conflicts with passing a planner, a planner creates plans, so passing an existing plan doesn't make sense")), diff --git a/src/planner/mod.rs b/src/planner/mod.rs index 2255d5b..c394997 100644 --- a/src/planner/mod.rs +++ b/src/planner/mod.rs @@ -168,6 +168,22 @@ impl BuiltinPlanner { BuiltinPlanner::SteamDeck(i) => i.boxed(), } } + + pub fn typetag_name(&self) -> &'static str { + match self { + BuiltinPlanner::LinuxMulti(i) => i.typetag_name(), + BuiltinPlanner::DarwinMulti(i) => i.typetag_name(), + BuiltinPlanner::SteamDeck(i) => i.typetag_name(), + } + } + + pub fn settings(&self) -> Result, InstallSettingsError> { + match self { + BuiltinPlanner::LinuxMulti(i) => i.settings(), + BuiltinPlanner::DarwinMulti(i) => i.settings(), + BuiltinPlanner::SteamDeck(i) => i.settings(), + } + } } /// An error originating from a [`Planner`]