update action match function
This commit is contained in:
@@ -6,3 +6,4 @@
|
|||||||
- make table use section header with brackets
|
- make table use section header with brackets
|
||||||
- tutorial
|
- tutorial
|
||||||
- remove "Arch" references
|
- remove "Arch" references
|
||||||
|
- update README for subcommands "group", "package"
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ use pacdef_macros::Action;
|
|||||||
pub enum Actions {
|
pub enum Actions {
|
||||||
Clean,
|
Clean,
|
||||||
Edit,
|
Edit,
|
||||||
Groups,
|
|
||||||
Import,
|
Import,
|
||||||
|
List,
|
||||||
New,
|
New,
|
||||||
Remove,
|
Remove,
|
||||||
Review,
|
Review,
|
||||||
|
|||||||
@@ -21,23 +21,18 @@ fn get_arg_parser() -> Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_group_cmd() -> Command {
|
fn get_group_cmd() -> Command {
|
||||||
let remove = Command::new(REMOVE)
|
|
||||||
.about("remove one or more previously imported groups")
|
|
||||||
.arg_required_else_help(true)
|
|
||||||
.arg(Arg::new("groups").num_args(1..));
|
|
||||||
|
|
||||||
let edit = Command::new(EDIT)
|
let edit = Command::new(EDIT)
|
||||||
.about("edit one or more existing group files")
|
.about("edit one or more existing group files")
|
||||||
.arg_required_else_help(true)
|
.arg_required_else_help(true)
|
||||||
.arg(Arg::new("group").num_args(1..));
|
.arg(Arg::new("group").num_args(1..));
|
||||||
|
|
||||||
let list = Command::new(GROUPS).about("list names of imported groups");
|
|
||||||
|
|
||||||
let import = Command::new(IMPORT)
|
let import = Command::new(IMPORT)
|
||||||
.about("import one or more group files")
|
.about("import one or more group files")
|
||||||
.arg_required_else_help(true)
|
.arg_required_else_help(true)
|
||||||
.arg(Arg::new("files").num_args(1..));
|
.arg(Arg::new("files").num_args(1..));
|
||||||
|
|
||||||
|
let list = Command::new(LIST).about("list names of imported groups");
|
||||||
|
|
||||||
let new = Command::new(NEW)
|
let new = Command::new(NEW)
|
||||||
.about("create new group files")
|
.about("create new group files")
|
||||||
.arg_required_else_help(true)
|
.arg_required_else_help(true)
|
||||||
@@ -50,6 +45,11 @@ fn get_group_cmd() -> Command {
|
|||||||
)
|
)
|
||||||
.arg(Arg::new("groups").num_args(1..));
|
.arg(Arg::new("groups").num_args(1..));
|
||||||
|
|
||||||
|
let remove = Command::new(REMOVE)
|
||||||
|
.about("remove one or more previously imported groups")
|
||||||
|
.arg_required_else_help(true)
|
||||||
|
.arg(Arg::new("groups").num_args(1..));
|
||||||
|
|
||||||
let show = Command::new(SHOW)
|
let show = Command::new(SHOW)
|
||||||
.about("show packages under an imported group")
|
.about("show packages under an imported group")
|
||||||
.arg_required_else_help(true)
|
.arg_required_else_help(true)
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ use crate::ui::get_user_confirmation;
|
|||||||
use crate::Config;
|
use crate::Config;
|
||||||
use crate::Group;
|
use crate::Group;
|
||||||
|
|
||||||
|
const UNREACHABLE_ARM: &str = "argument parser requires some subcommand to return an `ArgMatches`";
|
||||||
|
const ACTION_NOT_MATCHED: &str = "could not match action";
|
||||||
|
|
||||||
/// Most data that is required during runtime of the program.
|
/// Most data that is required during runtime of the program.
|
||||||
pub struct Pacdef {
|
pub struct Pacdef {
|
||||||
args: ArgMatches,
|
args: ArgMatches,
|
||||||
@@ -53,25 +56,36 @@ impl Pacdef {
|
|||||||
#[allow(clippy::unit_arg)]
|
#[allow(clippy::unit_arg)]
|
||||||
pub fn run_action_from_arg(mut self) -> Result<()> {
|
pub fn run_action_from_arg(mut self) -> Result<()> {
|
||||||
match self.args.subcommand() {
|
match self.args.subcommand() {
|
||||||
Some((CLEAN, _)) => self.clean_packages(),
|
Some(("group", args)) => match args.subcommand() {
|
||||||
Some((EDIT, args)) => self.edit_group_files(args).context("editing group files"),
|
Some((EDIT, args)) => self.edit_group_files(args).context("editing group files"),
|
||||||
Some((GROUPS, _)) => Ok(self.show_groups()),
|
Some((IMPORT, args)) => self.import_groups(args).context("importing groups"),
|
||||||
Some((IMPORT, args)) => self.import_groups(args).context("importing groups"),
|
Some((LIST, _)) => Ok(self.show_groups()),
|
||||||
Some((NEW, args)) => self.new_groups(args).context("creating new group files"),
|
Some((NEW, args)) => self.new_groups(args).context("creating new group files"),
|
||||||
Some((REMOVE, args)) => self.remove_groups(args).context("removing groups"),
|
Some((REMOVE, args)) => self.remove_groups(args).context("removing groups"),
|
||||||
Some((REVIEW, _)) => review::review(self.get_unmanaged_packages(), self.groups)
|
Some((SHOW, args)) => self.show_group_content(args).context("showing groups"),
|
||||||
.context("review unmanaged packages"),
|
|
||||||
Some((SHOW, args)) => self.show_group_content(args).context("showing groups"),
|
Some((_, _)) => panic!("{ACTION_NOT_MATCHED}"),
|
||||||
Some((SEARCH, args)) => {
|
None => unreachable!("{UNREACHABLE_ARM}"),
|
||||||
search::search_packages(args, &self.groups).context("searching packages")
|
},
|
||||||
}
|
|
||||||
Some((SYNC, _)) => self.install_packages(),
|
Some(("package", args)) => match args.subcommand() {
|
||||||
Some((UNMANAGED, _)) => self.show_unmanaged_packages(),
|
Some((CLEAN, _)) => self.clean_packages(),
|
||||||
|
Some((REVIEW, _)) => review::review(self.get_unmanaged_packages(), self.groups)
|
||||||
|
.context("review unmanaged packages"),
|
||||||
|
Some((SEARCH, args)) => {
|
||||||
|
search::search_packages(args, &self.groups).context("searching packages")
|
||||||
|
}
|
||||||
|
Some((SYNC, _)) => self.install_packages(),
|
||||||
|
Some((UNMANAGED, _)) => self.show_unmanaged_packages(),
|
||||||
|
|
||||||
|
Some((_, _)) => panic!("{ACTION_NOT_MATCHED}"),
|
||||||
|
None => unreachable!("{UNREACHABLE_ARM}"),
|
||||||
|
},
|
||||||
|
|
||||||
Some((VERSION, _)) => Ok(self.show_version()),
|
Some((VERSION, _)) => Ok(self.show_version()),
|
||||||
Some((_, _)) => panic!(),
|
|
||||||
None => {
|
Some((_, _)) => panic!("{ACTION_NOT_MATCHED}"),
|
||||||
unreachable!("argument parser requires some subcommand to return an `ArgMatches`")
|
None => unreachable!("{UNREACHABLE_ARM}"),
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user