mirror of https://git.sr.ht/~nixgoat/vento
archive: Add inventory importing
Allows exported inventories to be imported using the command `vento -g`
This commit is contained in:
parent
c5cc1ea97a
commit
13d0889ad1
|
@ -21,6 +21,8 @@ use crate::common;
|
|||
use anyhow::Result;
|
||||
use colored::Colorize;
|
||||
use std::{fs::File, path::PathBuf};
|
||||
use tar::Archive;
|
||||
use xz2::read::XzDecoder;
|
||||
use xz2::write::XzEncoder;
|
||||
|
||||
pub fn export_inv(slot: &str, output: PathBuf, message: bool) -> Result<()> {
|
||||
|
@ -69,3 +71,33 @@ pub fn export_install(output: PathBuf, message: bool) -> Result<()> {
|
|||
};
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn import_inv(input: PathBuf, slot: &str, message: bool) -> Result<()> {
|
||||
let slotdir: PathBuf = match slot {
|
||||
"active" | "a" => common::env_config()?.active_dir,
|
||||
"inactive" | "i" => common::env_config()?.inactive_dir,
|
||||
_ => PathBuf::new(),
|
||||
};
|
||||
|
||||
let tar_xz = File::open(&input)?;
|
||||
let tar = XzDecoder::new(tar_xz);
|
||||
let mut archive = Archive::new(tar);
|
||||
archive.unpack(&slotdir)?;
|
||||
|
||||
if message {
|
||||
println!(
|
||||
"✅ {} {} {} {} {}",
|
||||
"Imported".green(),
|
||||
&input.to_str().unwrap(),
|
||||
"into".green(),
|
||||
match slot {
|
||||
"a" | "active" => "active".green(),
|
||||
"i" | "inactive" => "inactive".blue(),
|
||||
_ => slot.red(),
|
||||
}
|
||||
.bold(),
|
||||
"slot".green()
|
||||
);
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -65,6 +65,12 @@ fn main() -> Result<()> {
|
|||
2 => archive::export_install(PathBuf::from("vento.tar.xz"), true)?,
|
||||
_ => throw_error(ErrorType::TooManyArgs)?,
|
||||
},
|
||||
"-g" | "--import-inv" => match args.len() {
|
||||
4 => archive::import_inv(PathBuf::from(&args[2]), &args[3], true)?,
|
||||
3 => archive::import_inv(PathBuf::from(&args[2]), "active", true)?,
|
||||
2 => throw_error(ErrorType::SpecifyFile)?,
|
||||
_ => throw_error(ErrorType::TooManyArgs)?,
|
||||
},
|
||||
"-s" => match args.len() {
|
||||
4 => inv::list(&args[2], &args[3])?,
|
||||
3 => inv::list(&args[2], "")?,
|
||||
|
|
Loading…
Reference in New Issue