refact(cmd): dont return exitstatus
This commit is contained in:
@@ -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();
|
||||||
|
|||||||
@@ -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(())
|
||||||
|
|||||||
Reference in New Issue
Block a user