Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Add an option to always suspend vagrant boxes
Browse files Browse the repository at this point in the history
  • Loading branch information
r-darwish committed Jun 13, 2020
1 parent 73a66e7 commit bb9c884
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ pub struct Git {
pub struct Vagrant {
directories: Option<Vec<String>>,
power_on: Option<bool>,
always_suspend: Option<bool>,
}

#[derive(Deserialize, Default, Debug)]
Expand Down Expand Up @@ -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<bool> {
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 {
Expand Down
12 changes: 8 additions & 4 deletions src/steps/vagrant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit bb9c884

Please sign in to comment.