feat(export): core logic

This commit is contained in:
steven-omaha
2023-06-06 15:30:24 +02:00
parent f527125e59
commit 0b7fcbbbd4
2 changed files with 24 additions and 6 deletions
@@ -8,6 +8,7 @@ pub enum Arguments {
#[derive(Debug)] #[derive(Debug)]
pub enum GroupAction { pub enum GroupAction {
Edit(Groups), Edit(Groups),
// TODO: optional output dir
Export(Groups), Export(Groups),
Import(Groups), Import(Groups),
List, List,
+23 -6
View File
@@ -1,7 +1,8 @@
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::fs::{remove_file, File}; use std::env::current_dir;
use std::fs::{remove_file, rename, File};
use std::os::unix::fs::symlink; use std::os::unix::fs::symlink;
use std::path::Path; use std::path::{Path, PathBuf};
use anyhow::{bail, ensure, Context, Result}; use anyhow::{bail, ensure, Context, Result};
use const_format::formatcp; use const_format::formatcp;
@@ -399,12 +400,28 @@ impl Pacdef {
} }
fn export_groups(&self, groups: &[String]) -> Result<()> { fn export_groups(&self, groups: &[String]) -> Result<()> {
let groups = get_group_file_paths_matching_args(groups, &self.groups) let groups: Vec<_> = groups
.context("resolving group files")?; .iter()
.map(|group_name| {
self.groups
.iter()
.find(|group| group.name == *group_name)
.unwrap()
})
.collect();
std::fs::rename(from, to) let output_dir = current_dir()?;
todo!() for group in &groups {
let mut exported_path = output_dir.clone();
exported_path.push(PathBuf::from(&group.name));
// TODO: check if output exists
// TODO: check if this was successful, resort to the other method otherwise
rename(&group.path, &exported_path)?;
symlink(&exported_path, &group.path)?;
}
Ok(())
} }
} }