fn editor_hook(path: &Path, editor: &str) -> Result<()> {
    if util::is_stdin(editor) {
        let mut src = io::stdin();
        let mut dst = OpenOptions::new()
            .mode(0o600)
            .create(true)
            .truncate(true)
            .write(true)
            .open(path)?;
        io::copy(&mut src, &mut dst)?;
    } else {
        let (editor, args) = util::split_editor(editor)?;
        let cmd = process::Command::new(&editor)
            .args(args.unwrap_or_else(Vec::new))
            .arg(path)
            .stdin(process::Stdio::inherit())
            .stdout(process::Stdio::inherit())
            .stderr(process::Stdio::piped())
            .output()
            .wrap_err_with(|| format!("Failed to spawn editor '{}'", &editor))?;

        if !cmd.status.success() {
            let stderr = String::from_utf8_lossy(&cmd.stderr);

            return Err(eyre!(
                "Editor '{}' exited with non-zero status code",
                &editor
            ))
            .with_section(|| stderr.trim().to_string().header("Stderr:"));
        }
    }

    Ok(())
}
/// Open a file for editing.
///
/// [Copied from cole-h/agenix-rs (ASL 2.0 / MIT)](
/// https://github.com/cole-h/agenix-rs/blob/8e0554179f1ac692fb865c256e9d7fb91b6a692d/src/cli.rs#L236-L257)
Open a file for editing.
Open a file for editing .
fn editor_hook(path: &Path, editor: &str) -> Result<()> {
    if util::is_stdin(editor) {
        let mut src = io::stdin();
        let mut dst = OpenOptions::new()
            .mode(0o600)
            .create(true)
            .truncate(true)
            .write(true)
            .open(path)?;
        io::copy(&mut src, &mut dst)?;
    } else {
        let (editor, args) = util::split_editor(editor)?;
        let cmd = process::Command::new(&editor)
            .args(args.unwrap_or_else(Vec::new))
            .arg(path)
            .stdin(process::Stdio::inherit())
            .stdout(process::Stdio::inherit())
            .stderr(process::Stdio::piped())
            .output()
            .wrap_err_with(|| format!("Failed to spawn editor '{}'", &editor))?;
        if !cmd.status.success() {
            let stderr = String::from_utf8_lossy(&cmd.stderr);
            return Err(eyre!(
                "Editor '{}' exited with non-zero status code",
                &editor
            ))
            .with_section(|| stderr.trim().to_string().header("Stderr:"));
        }
    }
    Ok(())
}
fn editor_hook ( path : & Path , editor : & str ) -> Result < ( ) > { if util :: is_stdin ( editor ) { let mut src = io :: stdin ( ) ; let mut dst = OpenOptions :: new ( ) . mode ( 0o600 ) . create ( true ) . truncate ( true ) . write ( true ) . open ( path ) ? ; io :: copy ( & mut src , & mut dst ) ? ; } else { let ( editor , args ) = util :: split_editor ( editor ) ? ; let cmd = process :: Command :: new ( & editor ) . args ( args . unwrap_or_else ( Vec :: new ) ) . arg ( path ) . stdin ( process :: Stdio :: inherit ( ) ) . stdout ( process :: Stdio :: inherit ( ) ) . stderr ( process :: Stdio :: piped ( ) ) . output ( ) . wrap_err_with ( | | format ! ( " " editor ) ) ? ; if ! cmd . status . success ( ) { let stderr = String :: from_utf8_lossy ( & cmd . stderr ) ; return Err ( eyre ! ( " " editor ) ) . with_section ( | | stderr . trim ( ) . to_string ( ) . header ( " " ) ) ; } } Ok ( ( ) ) }
Open a file for editing.
Open a file for editing .
path
&Path
editor
&str