add 'new' argument

This commit is contained in:
steven-omaha
2023-01-12 11:23:45 +01:00
parent b5d6aa9ffb
commit f05be4cce0
3 changed files with 25 additions and 1 deletions
+18 -1
View File
@@ -1,5 +1,5 @@
use std::collections::HashSet;
use std::fs::remove_file;
use std::fs::{remove_file, File};
use std::os::unix::fs::symlink;
use std::path::PathBuf;
@@ -38,6 +38,9 @@ impl Pacdef {
}
Some((action::GROUPS, _)) => Ok(self.show_groups()),
Some((action::IMPORT, files)) => self.import_groups(files).context("importing groups"),
Some((action::NEW, files)) => {
self.new_groups(files).context("creating new group files")
}
Some((action::REMOVE, groups)) => self.remove_groups(groups).context("removing groups"),
Some((action::SHOW, groups)) => {
self.show_group_content(groups).context("showing groups")
@@ -211,6 +214,20 @@ impl Pacdef {
Ok(())
}
fn new_groups(&self, files: &ArgMatches) -> Result<()> {
let paths = get_assumed_group_file_names(files)?;
for file in &paths {
ensure!(!file.exists(), "group already exists under {file:?}");
}
for file in paths {
File::create(file)?;
}
Ok(())
}
}
fn get_assumed_group_file_names(arg_match: &ArgMatches) -> Result<Vec<PathBuf>> {