diff options
author | notgne2 | 2021-05-10 21:40:30 -0700 |
---|---|---|
committer | GitHub | 2021-05-10 21:40:30 -0700 |
commit | f0456d67149edbf27a6cb0a4963386bc2e678267 (patch) | |
tree | 993a8d8aa793a0065c64c7326ed1ff15a5d00097 /src/bin/activate.rs | |
parent | 9e405fbc5ab5bacbd271fd78c6b6b6877c4d9f8d (diff) | |
parent | 5d5da4898d41cefd1f79c4cf6dd451405ffb8996 (diff) |
Merge pull request #81 from kitnil/dry-activate
Add dry-activate
Diffstat (limited to 'src/bin/activate.rs')
-rw-r--r-- | src/bin/activate.rs | 99 |
1 files changed, 56 insertions, 43 deletions
diff --git a/src/bin/activate.rs b/src/bin/activate.rs index 947e883..d17f3a8 100644 --- a/src/bin/activate.rs +++ b/src/bin/activate.rs @@ -66,6 +66,10 @@ struct ActivateOpts { /// Auto rollback if failure #[clap(long)] auto_rollback: bool, + + /// Show what will be activated on the machines + #[clap(long)] + dry_activate: bool, } /// Activate a profile @@ -348,70 +352,78 @@ pub async fn activate( temp_path: String, confirm_timeout: u16, magic_rollback: bool, + dry_activate: bool, ) -> Result<(), ActivateError> { - info!("Activating profile"); - - let nix_env_set_exit_status = Command::new("nix-env") - .arg("-p") - .arg(&profile_path) - .arg("--set") - .arg(&closure) - .status() - .await - .map_err(ActivateError::SetProfileError)?; - - match nix_env_set_exit_status.code() { - Some(0) => (), - a => { - if auto_rollback { - deactivate(&profile_path).await?; + if !dry_activate { + info!("Activating profile"); + let nix_env_set_exit_status = Command::new("nix-env") + .arg("-p") + .arg(&profile_path) + .arg("--set") + .arg(&closure) + .status() + .await + .map_err(ActivateError::SetProfileError)?; + match nix_env_set_exit_status.code() { + Some(0) => (), + a => { + if auto_rollback && !dry_activate { + deactivate(&profile_path).await?; + } + return Err(ActivateError::SetProfileExitError(a)); } - return Err(ActivateError::SetProfileExitError(a)); - } - }; + }; + } debug!("Running activation script"); - let activate_status = match Command::new(format!("{}/deploy-rs-activate", profile_path)) - .env("PROFILE", &profile_path) - .current_dir(&profile_path) + let activation_location = if dry_activate { &closure } else { &profile_path }; + + let activate_status = match Command::new(format!("{}/deploy-rs-activate", activation_location)) + .env("PROFILE", activation_location) + .env("DRY_ACTIVATE", if dry_activate { "1" } else { "0" }) + .current_dir(activation_location) .status() .await .map_err(ActivateError::RunActivateError) { Ok(x) => x, Err(e) => { - if auto_rollback { + if auto_rollback && !dry_activate { deactivate(&profile_path).await?; } return Err(e); } }; - match activate_status.code() { - Some(0) => (), - a => { - if auto_rollback { - deactivate(&profile_path).await?; + if !dry_activate { + match activate_status.code() { + Some(0) => (), + a => { + if auto_rollback { + deactivate(&profile_path).await?; + } + return Err(ActivateError::RunActivateExitError(a)); } - return Err(ActivateError::RunActivateExitError(a)); - } - }; + }; - info!("Activation succeeded!"); + if !dry_activate { + info!("Activation succeeded!"); + } - if magic_rollback { - info!("Magic rollback is enabled, setting up confirmation hook..."); + if magic_rollback { + info!("Magic rollback is enabled, setting up confirmation hook..."); - match activation_confirmation(profile_path.clone(), temp_path, confirm_timeout, closure) - .await - { - Ok(()) => {} - Err(err) => { - deactivate(&profile_path).await?; - return Err(ActivateError::ActivationConfirmationError(err)); - } - }; + match activation_confirmation(profile_path.clone(), temp_path, confirm_timeout, closure) + .await + { + Ok(()) => {} + Err(err) => { + deactivate(&profile_path).await?; + return Err(ActivateError::ActivationConfirmationError(err)); + } + }; + } } Ok(()) @@ -446,6 +458,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { opts.temp_path, activate_opts.confirm_timeout, activate_opts.magic_rollback, + activate_opts.dry_activate, ) .await .map_err(|x| Box::new(x) as Box<dyn std::error::Error>), |