(shell: &[String], cmd: &str, workdir: &Path, project_name: &str, color: Color)
| 51 | } |
| 52 | |
| 53 | pub fn spawn_maybe(shell: &[String], cmd: &str, workdir: &Path, project_name: &str, color: Color) -> Result<(), AppError> { |
| 54 | let program: &str = shell |
| 55 | .first() |
| 56 | .ok_or_else(|| AppError::UserError("shell entry in project settings must have at least one element".to_owned()))?; |
| 57 | let rest: &[String] = shell.split_at(1).1; |
| 58 | let mut result: Child = Command::new(program) |
| 59 | .args(rest) |
| 60 | .arg(cmd) |
| 61 | .current_dir(workdir) |
| 62 | .env("FW_PROJECT", project_name) |
| 63 | .stdout(Stdio::piped()) |
| 64 | .stderr(Stdio::piped()) |
| 65 | .stdin(Stdio::null()) |
| 66 | .spawn()?; |
| 67 | |
| 68 | let stdout_child = match result.stdout.take() { |
| 69 | Some(stdout) => { |
| 70 | let project_name = project_name.to_owned(); |
| 71 | Some(thread::spawn(move || { |
| 72 | let atty: bool = is_stdout_a_tty(); |
| 73 | forward_process_output_to_stdout(stdout, &project_name, color, atty, false) |
| 74 | })) |
| 75 | } |
| 76 | _ => None, |
| 77 | }; |
| 78 | |
| 79 | // stream stderr in this thread. no need to spawn another one. |
| 80 | if let Some(stderr) = result.stderr.take() { |
| 81 | let atty: bool = is_stderr_a_tty(); |
| 82 | forward_process_output_to_stdout(stderr, project_name, color, atty, true)? |
| 83 | } |
| 84 | |
| 85 | if let Some(child) = stdout_child { |
| 86 | child.join().expect("Must be able to join child")?; |
| 87 | } |
| 88 | |
| 89 | let status = result.wait()?; |
| 90 | if status.code().unwrap_or(0) > 0 { |
| 91 | Err(AppError::UserError("External command failed.".to_owned())) |
| 92 | } else { |
| 93 | Ok(()) |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | pub fn init_threads(parallel_raw: &Option<String>) -> Result<(), AppError> { |
| 98 | if let Some(ref raw_num) = *parallel_raw { |
no test coverage detected