Vagrant boxes (#905)

This commit is contained in:
Roey Darwish Dror
2022-04-23 15:09:54 +03:00
committed by GitHub
parent 020a0619b8
commit 14809322b4
4 changed files with 91 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ use std::{fmt::Display, rc::Rc, str::FromStr};
use anyhow::Result;
use log::{debug, error};
use regex::Regex;
use strum::EnumString;
use crate::execution_context::ExecutionContext;
@@ -200,3 +201,35 @@ pub fn topgrade_vagrant_box(ctx: &ExecutionContext, vagrant_box: &VagrantBox) ->
.args(&["ssh", "-c", &command])
.check_run()
}
pub fn upgrade_vagrant_boxes(ctx: &ExecutionContext) -> Result<()> {
let vagrant = utils::require("vagrant")?;
print_separator("Vagrant boxes");
let outdated = Command::new(&vagrant)
.args(&["box", "outdated", "--global"])
.check_output()?;
let re = Regex::new(r"\* '(.*?)' for '(.*?)' is outdated").unwrap();
let mut found = false;
for ele in re.captures_iter(&outdated) {
found = true;
let _ = ctx
.run_type()
.execute(&vagrant)
.args(&["box", "update", "--box"])
.arg(&ele.get(1).unwrap().as_str())
.arg("--provider")
.arg(ele.get(2).unwrap().as_str())
.check_run();
}
if !found {
println!("No outdated boxes")
} else {
ctx.run_type().execute(&vagrant).args(&["box", "prune"]).check_run()?;
}
Ok(())
}