improve error handling
This commit is contained in:
@@ -18,10 +18,10 @@ pub(crate) struct Pacman {
|
||||
const BINARY: Text = "paru";
|
||||
const SECTION: Text = "pacman";
|
||||
|
||||
const SWITCHES_INFO: Switches = &["-Qi"];
|
||||
const SWITCHES_INSTALL: Switches = &["-S"];
|
||||
const SWITCHES_MAKE_DEPENDENCY: Switches = &["-D", "--asdeps"];
|
||||
const SWITCHES_REMOVE: Switches = &["-Rsn"];
|
||||
const SWITCHES_INFO: Switches = &["--query", "--info"];
|
||||
const SWITCHES_INSTALL: Switches = &["--sync"];
|
||||
const SWITCHES_MAKE_DEPENDENCY: Switches = &["--database", "--asdeps"];
|
||||
const SWITCHES_REMOVE: Switches = &["--remove", "--recursive"];
|
||||
|
||||
impl Backend for Pacman {
|
||||
impl_backend_constants!();
|
||||
|
||||
@@ -31,10 +31,12 @@ impl ToDoPerBackend {
|
||||
|
||||
pub(crate) fn install_missing_packages(&self) -> Result<()> {
|
||||
self.handle_backend_command(Backend::install_packages, "install", "installing")
|
||||
.context("installing packages")
|
||||
}
|
||||
|
||||
pub(crate) fn remove_unmanaged_packages(&self) -> Result<()> {
|
||||
self.handle_backend_command(Backend::remove_packages, "remove", "removing")
|
||||
.context("removing packages")
|
||||
}
|
||||
|
||||
fn handle_backend_command<'a, F>(
|
||||
|
||||
+6
-2
@@ -3,7 +3,7 @@ use std::fs::{remove_file, File};
|
||||
use std::os::unix::fs::symlink;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::{ensure, Context, Result};
|
||||
use anyhow::{anyhow, ensure, Context, Result};
|
||||
use clap::ArgMatches;
|
||||
|
||||
use crate::action::*;
|
||||
@@ -189,7 +189,11 @@ impl Pacdef {
|
||||
let mut iter = groups.get_many::<String>("group").unwrap().peekable();
|
||||
|
||||
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}");
|
||||
if iter.peek().is_some() {
|
||||
println!();
|
||||
|
||||
Reference in New Issue
Block a user