refact(cmd): dont return exitstatus

This commit is contained in:
steven-omaha
2024-04-09 14:09:04 +02:00
parent b98f8b1277
commit 9758257957
2 changed files with 7 additions and 15 deletions
+5 -6
View File
@@ -1,17 +1,17 @@
use std::path::Path; use std::path::Path;
use std::process::{Command, ExitStatus}; use std::process::Command;
use anyhow::{anyhow, ensure, Context, Result}; use anyhow::{ensure, Context, Result};
use crate::env::{get_editor, should_print_debug_info}; use crate::env::{get_editor, should_print_debug_info};
/// Run the editor and pass the provided files as arguments. The workdir is set /// Run the editor and pass the provided files as arguments. The workdir is set
/// to the parent of the first file. /// to the parent of the first file.
pub fn run_edit_command<P>(files: &[P]) -> Result<ExitStatus> pub fn run_edit_command<P>(files: &[P]) -> Result<()>
where where
P: AsRef<Path>, P: AsRef<Path>,
{ {
fn inner(files: &[&Path]) -> Result<ExitStatus> { fn inner(files: &[&Path]) -> Result<()> {
let mut cmd = Command::new(get_editor().context("getting suitable editor")?); let mut cmd = Command::new(get_editor().context("getting suitable editor")?);
cmd.current_dir( cmd.current_dir(
files[0] files[0]
@@ -21,8 +21,7 @@ where
for f in files { for f in files {
cmd.arg(f.to_string_lossy().to_string()); cmd.arg(f.to_string_lossy().to_string());
} }
// TODO this could also use the run_external_command function run_external_command(cmd)
cmd.status().map_err(|e| anyhow!(e))
} }
let files: Vec<_> = files.iter().map(|p| p.as_ref()).collect(); let files: Vec<_> = files.iter().map(|p| p.as_ref()).collect();
+2 -9
View File
@@ -181,11 +181,8 @@ impl Pacdef {
.map(|g| g.path.as_path()) .map(|g| g.path.as_path())
.collect(); .collect();
let success = run_edit_command(&group_files) run_edit_command(&group_files).context("running editor")?;
.context("running editor")?
.success();
ensure!(success, "editor exited with error");
Ok(()) Ok(())
} }
@@ -422,11 +419,7 @@ impl Pacdef {
} }
if edit { if edit {
let success = run_edit_command(&paths) run_edit_command(&paths).context("running editor")?;
.context("running editor")?
.success();
ensure!(success, "editor exited with error");
} }
Ok(()) Ok(())