improve error handling

This commit is contained in:
steven-omaha
2023-02-02 15:11:02 +01:00
parent 15c48786cf
commit 47f8e2f796
3 changed files with 12 additions and 6 deletions
+4 -4
View File
@@ -18,10 +18,10 @@ pub(crate) struct Pacman {
const BINARY: Text = "paru"; const BINARY: Text = "paru";
const SECTION: Text = "pacman"; const SECTION: Text = "pacman";
const SWITCHES_INFO: Switches = &["-Qi"]; const SWITCHES_INFO: Switches = &["--query", "--info"];
const SWITCHES_INSTALL: Switches = &["-S"]; const SWITCHES_INSTALL: Switches = &["--sync"];
const SWITCHES_MAKE_DEPENDENCY: Switches = &["-D", "--asdeps"]; const SWITCHES_MAKE_DEPENDENCY: Switches = &["--database", "--asdeps"];
const SWITCHES_REMOVE: Switches = &["-Rsn"]; const SWITCHES_REMOVE: Switches = &["--remove", "--recursive"];
impl Backend for Pacman { impl Backend for Pacman {
impl_backend_constants!(); impl_backend_constants!();
+2
View File
@@ -31,10 +31,12 @@ impl ToDoPerBackend {
pub(crate) fn install_missing_packages(&self) -> Result<()> { pub(crate) fn install_missing_packages(&self) -> Result<()> {
self.handle_backend_command(Backend::install_packages, "install", "installing") self.handle_backend_command(Backend::install_packages, "install", "installing")
.context("installing packages")
} }
pub(crate) fn remove_unmanaged_packages(&self) -> Result<()> { pub(crate) fn remove_unmanaged_packages(&self) -> Result<()> {
self.handle_backend_command(Backend::remove_packages, "remove", "removing") self.handle_backend_command(Backend::remove_packages, "remove", "removing")
.context("removing packages")
} }
fn handle_backend_command<'a, F>( fn handle_backend_command<'a, F>(
+6 -2
View File
@@ -3,7 +3,7 @@ use std::fs::{remove_file, File};
use std::os::unix::fs::symlink; use std::os::unix::fs::symlink;
use std::path::PathBuf; use std::path::PathBuf;
use anyhow::{ensure, Context, Result}; use anyhow::{anyhow, ensure, Context, Result};
use clap::ArgMatches; use clap::ArgMatches;
use crate::action::*; use crate::action::*;
@@ -189,7 +189,11 @@ impl Pacdef {
let mut iter = groups.get_many::<String>("group").unwrap().peekable(); let mut iter = groups.get_many::<String>("group").unwrap().peekable();
while let Some(arg_group) = iter.next() { while let Some(arg_group) = iter.next() {
let group = self.groups.iter().find(|g| g.name == *arg_group).unwrap(); let group = self
.groups
.iter()
.find(|g| g.name == *arg_group)
.ok_or_else(|| anyhow!("group {} not found", *arg_group))?;
println!("{group}"); println!("{group}");
if iter.peek().is_some() { if iter.peek().is_some() {
println!(); println!();