/// Execute a shell command and return the trimmed stdout from that command
Execute a shell command and return the trimmed stdout from that command
Execute a shell command and return the trimmed stdout from that command
fn execute_binary(bin: &str, base_path: &Path, extra_arg: Option<String>) -> Fallible<String> {
    let mut trimmed = bin.trim().to_string();
    let mut words = trimmed.parse_cmdline_words();
    let cmd = match words.next() {
        Some(word) => {
            // Treat any path that starts with a './' or '../' as a relative path (using OS separator)
            if word.starts_with(REL_PATH.as_str()) || word.starts_with(REL_PATH_PARENT.as_str()) {
                canonicalize(base_path.join(word)).with_context(|_| {
                    ErrorDetails::HookPathError {
                        command: String::from(word),
                    }
                })?
            } else {
                PathBuf::from(word)
            }
        }
        None => throw!(ErrorDetails::InvalidHookCommand {
            command: String::from(bin.trim())
        }),
    };
    let mut args: Vec<OsString> = words.map(OsString::from).collect();
    if let Some(arg) = extra_arg {
        args.push(OsString::from(arg));
    }
    let mut command = create_command(cmd);
    command
        .args(&args)
        .current_dir(base_path)
        .stdin(Stdio::null())
        .stdout(Stdio::piped())
        .stderr(Stdio::inherit());
    debug!("Running hook command: {:?}", command);
    let output = command
        .output()
        .with_context(|_| ErrorDetails::ExecuteHookError {
            command: String::from(bin.trim()),
        })?;
    if !output.status.success() {
        throw!(ErrorDetails::HookCommandFailed {
            command: String::from(bin.trim()),
        });
    }
    let url =
        String::from_utf8(output.stdout).with_context(|_| ErrorDetails::InvalidHookOutput {
            command: String::from(bin.trim()),
        })?;
    Ok(url.trim().to_string())
}
fn execute_binary ( bin : & str , base_path : & Path , extra_arg : Option < String > ) -> Fallible < String > { let mut trimmed = bin . trim ( ) . to_string ( ) ; let mut words = trimmed . parse_cmdline_words ( ) ; let cmd = match words . next ( ) { Some ( word ) => { // Treat any path that starts with a './' or '../' as a relative path (using OS separator) if word . starts_with ( REL_PATH . as_str ( ) ) || word . starts_with ( REL_PATH_PARENT . as_str ( ) ) { canonicalize ( base_path . join ( word ) ) . with_context ( | _ | { ErrorDetails :: HookPathError { command : String :: from ( word ) , } } ) ? } else { PathBuf :: from ( word ) } } None => throw ! ( ErrorDetails InvalidHookCommand { command String from ( bin trim ( ) ) } ) , } ; let mut args : Vec < OsString > = words . map ( OsString :: from ) . collect ( ) ; if let Some ( arg ) = extra_arg { args . push ( OsString :: from ( arg ) ) ; } let mut command = create_command ( cmd ) ; command . args ( & args ) . current_dir ( base_path ) . stdin ( Stdio :: null ( ) ) . stdout ( Stdio :: piped ( ) ) . stderr ( Stdio :: inherit ( ) ) ; debug ! ( " " command ) ; let output = command . output ( ) . with_context ( | _ | ErrorDetails :: ExecuteHookError { command : String :: from ( bin . trim ( ) ) , } ) ? ; if ! output . status . success ( ) { throw ! ( ErrorDetails HookCommandFailed { command String from ( bin trim ( ) ) } ) ; } let url = String :: from_utf8 ( output . stdout ) . with_context ( | _ | ErrorDetails :: InvalidHookOutput { command : String :: from ( bin . trim ( ) ) , } ) ? ; Ok ( url . trim ( ) . to_string ( ) ) }
Execute a shell command and return the trimmed stdout from that command
Execute a shell command and return the trimmed stdout from that command
bin
&str
base_path
&Path
extra_arg
Option<String>