start propagating errors
This commit is contained in:
+13
-10
@@ -1,7 +1,7 @@
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Context, Result};
|
||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
|
|
||||||
use crate::action;
|
use crate::action;
|
||||||
@@ -61,13 +61,13 @@ impl Pacdef {
|
|||||||
run_install_command(diff);
|
run_install_command(diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_action_from_arg(self) {
|
pub fn run_action_from_arg(self) -> Result<()> {
|
||||||
match self.args.subcommand() {
|
match self.args.subcommand() {
|
||||||
Some((action::EDIT, groups)) => self.edit_group_files(groups).unwrap(),
|
Some((action::EDIT, groups)) => self.edit_group_files(groups).context("editing"),
|
||||||
Some((action::GROUPS, _)) => self.show_groups(),
|
Some((action::GROUPS, _)) => Ok(self.show_groups()),
|
||||||
Some((action::SYNC, _)) => self.install_packages(),
|
Some((action::SYNC, _)) => Ok(self.install_packages()),
|
||||||
Some((action::UNMANAGED, _)) => self.show_unmanaged_packages(),
|
Some((action::UNMANAGED, _)) => Ok(self.show_unmanaged_packages()),
|
||||||
Some((action::VERSION, _)) => self.show_version(),
|
Some((action::VERSION, _)) => Ok(self.show_version()),
|
||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,17 +75,20 @@ impl Pacdef {
|
|||||||
pub(crate) fn edit_group_files(&self, groups: &ArgMatches) -> Result<()> {
|
pub(crate) fn edit_group_files(&self, groups: &ArgMatches) -> Result<()> {
|
||||||
let files: Vec<_> = groups
|
let files: Vec<_> = groups
|
||||||
.get_many::<String>("group")
|
.get_many::<String>("group")
|
||||||
.unwrap()
|
.context("getting group from args")?
|
||||||
.map(|file| {
|
.map(|file| {
|
||||||
let mut buf = crate::path::get_pacdef_group_dir().unwrap();
|
let mut buf = crate::path::get_pacdef_group_dir().unwrap();
|
||||||
buf.push(file);
|
buf.push(file);
|
||||||
buf
|
buf
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
if run_edit_command(&files)?.success() {
|
if run_edit_command(&files)
|
||||||
|
.context("running editor")?
|
||||||
|
.success()
|
||||||
|
{
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
bail!("command exited with error")
|
bail!("editor exited with error")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
use anyhow::Result;
|
use anyhow::{Context, Result};
|
||||||
|
|
||||||
use pacdef::{args, Group, Pacdef};
|
use pacdef::{args, Group, Pacdef};
|
||||||
|
|
||||||
@@ -6,6 +6,6 @@ fn main() -> Result<()> {
|
|||||||
let args = args::get_args();
|
let args = args::get_args();
|
||||||
let groups = Group::load_from_dir();
|
let groups = Group::load_from_dir();
|
||||||
let pacdef = Pacdef::new(args, groups);
|
let pacdef = Pacdef::new(args, groups);
|
||||||
pacdef.run_action_from_arg();
|
pacdef.run_action_from_arg().context("running action")?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user