diff --git a/src/config.rs b/src/config.rs index 69d374a9..960232af 100644 --- a/src/config.rs +++ b/src/config.rs @@ -91,6 +91,7 @@ pub struct Git { pub struct Vagrant { directories: Option>, power_on: Option, + always_suspend: Option, } #[derive(Deserialize, Default, Debug)] @@ -518,6 +519,14 @@ impl Config { .and_then(|vagrant| vagrant.directories.as_ref()) } + /// Always suspend vagrant boxes instead of powering off + pub fn vagrant_always_suspend(&self) -> Option { + self.config_file + .vagrant + .as_ref() + .and_then(|vagrant| vagrant.always_suspend) + } + /// Extra yay arguments #[allow(dead_code)] pub fn enable_tlmgr_linux(&self) -> bool { diff --git a/src/steps/vagrant.rs b/src/steps/vagrant.rs index da3b0417..5115a4b2 100644 --- a/src/steps/vagrant.rs +++ b/src/steps/vagrant.rs @@ -118,10 +118,14 @@ impl<'a> TemporaryPowerOn<'a> { impl<'a> Drop for TemporaryPowerOn<'a> { fn drop(&mut self) { - let subcommand = match self.status { - BoxStatus::PowerOff | BoxStatus::Aborted => "halt", - BoxStatus::Saved => "suspend", - BoxStatus::Running => unreachable!(), + let subcommand = if self.ctx.config().vagrant_always_suspend().unwrap_or(false) { + "suspend" + } else { + match self.status { + BoxStatus::PowerOff | BoxStatus::Aborted => "halt", + BoxStatus::Saved => "suspend", + BoxStatus::Running => unreachable!(), + } }; println!("Powering off {}", self.vagrant_box);