Skip to content

Commit

Permalink
Refactor task executor implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dottorblaster committed Dec 11, 2018
1 parent 0c08dac commit 271c4d6
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::sync::{Mutex, Arc};
use std::thread;
use std::process::Command;
use std::process::Output;
use std::io;

use self::ansi_term::Colour::{Red, Green, Yellow, Black};
use self::ansi_term::ANSIString;
Expand Down Expand Up @@ -38,6 +39,16 @@ fn task_failure(task: Task, output: Output, json: bool) {
}
}

fn buildTaskOutput(output: io::Result<Output>, task: Task) -> TaskOutput {
TaskOutput {
outcome: String::from_utf8(output.stdout).unwrap(),
code: output.status.code().unwrap().to_string(),
name: task.name,
description: task.description,
command: task.command,
}
}

pub fn run(tasks: Vec<Task>, cwd_path: String, json_output: bool) -> bool {
let outputs = Arc::new(Mutex::new(task_output::Tasks::with_capacity(tasks.len())));
let mut handles = Vec::with_capacity(tasks.len());
Expand All @@ -55,14 +66,8 @@ pub fn run(tasks: Vec<Task>, cwd_path: String, json_output: bool) -> bool {
.current_dir(path)
.output()
.expect("command failed");
let cloned_output = command_output.clone();
list.push(TaskOutput {
outcome: String::from_utf8(cloned_output.stdout).unwrap(),
code: cloned_output.status.code().unwrap().to_string(),
name: task_data.name,
description: task_data.description,
command: task_data.command,
});
// let cloned_output = command_output.clone();
list.push(buildTaskOutput(command_output, task_data));
match command_output.status.code() {
Some(0) => task_success(data, command_output, json_output),
Some(_) => task_failure(data, command_output, json_output),
Expand Down

0 comments on commit 271c4d6

Please sign in to comment.