handle errors in editing files

This commit is contained in:
steven-omaha
2022-12-02 17:51:10 +01:00
parent 81c6b04e64
commit 1eb71b7651
4 changed files with 29 additions and 9 deletions
+10 -5
View File
@@ -1,14 +1,15 @@
use std::collections::HashSet;
use std::process::exit;
use anyhow::{bail, Result};
use clap::ArgMatches;
use crate::action;
use crate::cmd::{run_edit_command, run_install_command};
use crate::db::{get_all_installed_packages, get_explicitly_installed_packages};
use crate::Group;
use crate::Package;
use clap::ArgMatches;
pub struct Pacdef {
pub(crate) args: ArgMatches,
pub(crate) groups: Option<HashSet<Group>>,
@@ -62,7 +63,7 @@ impl Pacdef {
pub fn run_action_from_arg(self) {
match self.args.subcommand() {
Some((action::EDIT, groups)) => self.edit_group_files(groups),
Some((action::EDIT, groups)) => self.edit_group_files(groups).unwrap(),
Some((action::GROUPS, _)) => self.show_groups(),
Some((action::SYNC, _)) => self.install_packages(),
Some((action::UNMANAGED, _)) => self.show_unmanaged_packages(),
@@ -71,7 +72,7 @@ impl Pacdef {
}
}
pub(crate) fn edit_group_files(&self, groups: &ArgMatches) {
pub(crate) fn edit_group_files(&self, groups: &ArgMatches) -> Result<()> {
let files: Vec<_> = groups
.get_many::<String>("group")
.unwrap()
@@ -81,7 +82,11 @@ impl Pacdef {
buf
})
.collect();
run_edit_command(&files)
if run_edit_command(&files)?.success() {
Ok(())
} else {
bail!("command exited with error")
}
}
pub(crate) fn show_version(self) {