archive: Add install importing

Allows exported installs to be imported using the command `vento -G`.
Mind the uppercase "G" there!
This commit is contained in:
Lux Aliaga 2023-02-19 13:03:36 -03:00
parent 13d0889ad1
commit 2a4ee258a3
Signed by: lux
GPG Key ID: B56C805968637437
2 changed files with 24 additions and 0 deletions

View File

@ -101,3 +101,22 @@ pub fn import_inv(input: PathBuf, slot: &str, message: bool) -> Result<()> {
};
Ok(())
}
pub fn import_install(input: PathBuf, message: bool) -> Result<()> {
let dir: PathBuf = common::env_config()?.vento_dir;
let tar_xz = File::open(&input)?;
let tar = XzDecoder::new(tar_xz);
let mut archive = Archive::new(tar);
archive.unpack(&dir)?;
if message {
println!(
"✅ {} {} {}",
"Imported".green(),
&input.to_str().unwrap(),
"into Vento install".green(),
);
};
Ok(())
}

View File

@ -71,6 +71,11 @@ fn main() -> Result<()> {
2 => throw_error(ErrorType::SpecifyFile)?,
_ => throw_error(ErrorType::TooManyArgs)?,
},
"-G" | "--import-install" => match args.len() {
3 => archive::import_install(PathBuf::from(&args[2]), 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], "")?,