add error NoGroupFilesInArguments

This commit is contained in:
steven-omaha
2023-02-22 12:29:02 +01:00
parent 8815daafcb
commit a4c900c9a7
5 changed files with 15 additions and 7 deletions
+7 -1
View File
@@ -27,11 +27,17 @@ fn main() -> ExitCode {
/// Skip printing the error chain when searching packages yields no results, otherwise report error
/// chain.
#[allow(clippy::option_if_let_else)]
fn handle_final_result(result: Result<()>) -> ExitCode {
match result {
Ok(_) => ExitCode::SUCCESS,
Err(ref e) => {
if e.root_cause().to_string() == pacdef_core::Error::NoPackagesFound.to_string() {
if let Some(pacdef_err) = e.root_cause().downcast_ref::<pacdef_core::Error>() {
match pacdef_err {
pacdef_core::Error::NoPackagesFound => (),
pacdef_core::Error::NoGroupFilesInArguments => eprintln!("{pacdef_err}"),
_ => eprintln!("unexpected error"),
};
ExitCode::FAILURE
} else {
result.report()
+2 -1
View File
@@ -45,7 +45,8 @@ fn get_group_cmd() -> Command {
.short('e')
.long("edit")
.help("edit the new group files after creation")
.action(clap::ArgAction::SetTrue),
.action(clap::ArgAction::SetTrue)
.num_args(0),
)
.arg(Arg::new("groups").num_args(1..))
.visible_alias("n");
+3 -2
View File
@@ -315,8 +315,9 @@ fn get_group_file_paths_matching_args<'a>(
groups: &'a HashSet<Group>,
) -> Result<Vec<&'a Path>> {
let file_names: Vec<_> = arg_match
.get_many::<String>("group")
.context("getting groups from args")?
.get_many::<String>("groups")
.context("getting groups from args")
.map_err(|_| crate::errors::Error::NoGroupFilesInArguments)?
.collect();
let name_group_map: HashMap<&str, &Group> =
+3
View File
@@ -7,12 +7,15 @@ use std::fmt::Display;
pub enum Error {
/// Package search yields no results.
NoPackagesFound,
/// No group files were provided as arguments.
NoGroupFilesInArguments,
}
impl Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::NoPackagesFound => f.write_str("no packages matching query"),
Self::NoGroupFilesInArguments => f.write_str("no group files in arguments"),
}
}
}