1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use super::{github_actions, ExitStatus, Param, PrettyExec};
use std::io;

pub fn exec(param: Param) -> Result<ExitStatus, String> {
    let Param {
        program,
        arguments,
        syntax_highlight,
        support_github_action,
        ..
    } = param;
    let mut pretty_exec = PrettyExec::new(program);

    for argument in arguments {
        pretty_exec.arg(argument);
    }

    let mut exec: Box<dyn FnMut() -> io::Result<ExitStatus>> = if support_github_action {
        let mut pretty_exec = pretty_exec
            .set_log_before(github_actions::GroupOpening(syntax_highlight))
            .set_log_after(github_actions::GroupClosing);
        Box::new(move || pretty_exec.spawn())
    } else {
        let mut pretty_exec = pretty_exec.set_log_before(syntax_highlight);
        Box::new(move || pretty_exec.spawn())
    };

    exec().map_err(|error: io::Error| error.to_string())
}