add remove
This commit is contained in:
@@ -2,6 +2,7 @@ pub(crate) const CLEAN: &str = "clean";
|
|||||||
pub(crate) const EDIT: &str = "edit";
|
pub(crate) const EDIT: &str = "edit";
|
||||||
pub(crate) const GROUPS: &str = "groups";
|
pub(crate) const GROUPS: &str = "groups";
|
||||||
pub(crate) const IMPORT: &str = "import";
|
pub(crate) const IMPORT: &str = "import";
|
||||||
|
pub(crate) const REMOVE: &str = "remove";
|
||||||
pub(crate) const SHOW: &str = "show";
|
pub(crate) const SHOW: &str = "show";
|
||||||
pub(crate) const SYNC: &str = "sync";
|
pub(crate) const SYNC: &str = "sync";
|
||||||
pub(crate) const UNMANAGED: &str = "unmanaged";
|
pub(crate) const UNMANAGED: &str = "unmanaged";
|
||||||
|
|||||||
+7
-1
@@ -25,6 +25,12 @@ fn get_arg_parser() -> Command<'static> {
|
|||||||
.arg_required_else_help(true)
|
.arg_required_else_help(true)
|
||||||
.arg(Arg::new("files").multiple_values(true)),
|
.arg(Arg::new("files").multiple_values(true)),
|
||||||
)
|
)
|
||||||
|
.subcommand(
|
||||||
|
Command::new(REMOVE)
|
||||||
|
.about("remove one or more previously imported groups")
|
||||||
|
.arg_required_else_help(true)
|
||||||
|
.arg(Arg::new("groups").multiple_values(true)),
|
||||||
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
Command::new(SHOW)
|
Command::new(SHOW)
|
||||||
.about("show packages under an imported group")
|
.about("show packages under an imported group")
|
||||||
@@ -45,7 +51,7 @@ pub fn get() -> clap::ArgMatches {
|
|||||||
get_arg_parser().get_matches()
|
get_arg_parser().get_matches()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_file_paths(arg_match: &ArgMatches) -> Vec<PathBuf> {
|
pub(crate) fn get_absolutized_file_paths(arg_match: &ArgMatches) -> Vec<PathBuf> {
|
||||||
arg_match
|
arg_match
|
||||||
.get_many::<String>("files")
|
.get_many::<String>("files")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|||||||
+34
-3
@@ -1,5 +1,7 @@
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
use std::fs::remove_file;
|
||||||
use std::os::unix::fs::symlink;
|
use std::os::unix::fs::symlink;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use anyhow::{ensure, Context, Result};
|
use anyhow::{ensure, Context, Result};
|
||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
@@ -26,9 +28,7 @@ impl Pacdef {
|
|||||||
|
|
||||||
#[allow(clippy::unit_arg)]
|
#[allow(clippy::unit_arg)]
|
||||||
pub fn run_action_from_arg(self) -> Result<()> {
|
pub fn run_action_from_arg(self) -> Result<()> {
|
||||||
// TODO import
|
|
||||||
// TODO new
|
// TODO new
|
||||||
// TODO remove
|
|
||||||
// TODO review
|
// TODO review
|
||||||
// TODO search
|
// TODO search
|
||||||
match self.args.subcommand() {
|
match self.args.subcommand() {
|
||||||
@@ -38,6 +38,7 @@ impl Pacdef {
|
|||||||
}
|
}
|
||||||
Some((action::GROUPS, _)) => Ok(self.show_groups()),
|
Some((action::GROUPS, _)) => Ok(self.show_groups()),
|
||||||
Some((action::IMPORT, files)) => self.import_groups(files).context("importing groups"),
|
Some((action::IMPORT, files)) => self.import_groups(files).context("importing groups"),
|
||||||
|
Some((action::REMOVE, groups)) => self.remove_groups(groups).context("removing groups"),
|
||||||
Some((action::SHOW, groups)) => {
|
Some((action::SHOW, groups)) => {
|
||||||
self.show_group_content(groups).context("showing groups")
|
self.show_group_content(groups).context("showing groups")
|
||||||
}
|
}
|
||||||
@@ -173,7 +174,7 @@ impl Pacdef {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn import_groups(&self, args: &ArgMatches) -> Result<()> {
|
fn import_groups(&self, args: &ArgMatches) -> Result<()> {
|
||||||
let files = args::get_file_paths(args);
|
let files = args::get_absolutized_file_paths(args);
|
||||||
let groups_dir = get_pacdef_group_dir()?;
|
let groups_dir = get_pacdef_group_dir()?;
|
||||||
|
|
||||||
for target in files {
|
for target in files {
|
||||||
@@ -196,6 +197,36 @@ impl Pacdef {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn remove_groups(&self, arg_match: &ArgMatches) -> Result<()> {
|
||||||
|
let paths = get_assumed_group_file_names(arg_match)?;
|
||||||
|
|
||||||
|
for file in paths.iter() {
|
||||||
|
ensure!(file.exists(), "did not find the group under {file:?}");
|
||||||
|
}
|
||||||
|
|
||||||
|
for file in paths {
|
||||||
|
remove_file(file)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_assumed_group_file_names(arg_match: &ArgMatches) -> Result<Vec<PathBuf>> {
|
||||||
|
let groups_dir = get_pacdef_group_dir()?;
|
||||||
|
|
||||||
|
let paths: Vec<_> = arg_match
|
||||||
|
.get_many::<String>("groups")
|
||||||
|
.unwrap()
|
||||||
|
.map(|s| {
|
||||||
|
let mut possible_group_file = groups_dir.clone();
|
||||||
|
possible_group_file.push(s);
|
||||||
|
possible_group_file
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
Ok(paths)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn show_error(error: anyhow::Error, backend: Box<dyn Backend>) {
|
fn show_error(error: anyhow::Error, backend: Box<dyn Backend>) {
|
||||||
|
|||||||
Reference in New Issue
Block a user