Skip to content

Commit

Permalink
fixup! Bring json_output in the task runner, adapt thread logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dottorblaster committed Dec 10, 2018
1 parent 2e18849 commit dc21174
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,28 @@ use std::process::Output;
use self::ansi_term::Colour::{Red, Green, Yellow, Black};
use self::ansi_term::ANSIString;

fn task_success(task: Task, output: Output) {
let stdout = ANSIString::from(String::from_utf8(output.stdout).unwrap());
println!(
"{} {}\n{}\n",
Black.bold().on(Green).paint(" SUCCESS "),
Yellow.paint(format!("{}", task.name)),
stdout
);
fn task_success(task: Task, output: Output, json: bool) {
if json == false {
let stdout = ANSIString::from(String::from_utf8(output.stdout).unwrap());
println!(
"{} {}\n{}\n",
Black.bold().on(Green).paint(" SUCCESS "),
Yellow.paint(format!("{}", task.name)),
stdout
);
}
}

fn task_failure(task: Task, output: Output) {
let stderr = ANSIString::from(String::from_utf8(output.stderr).unwrap());
println!(
"{} {}\n{}\n",
Black.bold().on(Red).paint(" FAIL "),
Yellow.paint(format!("{}", task.name)),
stderr
);
fn task_failure(task: Task, output: Output, json: bool) {
if json == false {
let stderr = ANSIString::from(String::from_utf8(output.stderr).unwrap());
println!(
"{} {}\n{}\n",
Black.bold().on(Red).paint(" FAIL "),
Yellow.paint(format!("{}", task.name)),
stderr
);
}
}

pub fn run(tasks: Vec<Task>, cwd_path: String, json_output: bool) -> bool {
Expand Down Expand Up @@ -60,15 +64,18 @@ pub fn run(tasks: Vec<Task>, cwd_path: String, json_output: bool) -> bool {
command: task_data.command,
});
match command_output.status.code() {
Some(0) => task_success(data, command_output),
Some(_) => task_failure(data, command_output),
Some(0) => task_success(data, command_output, json_output),
Some(_) => task_failure(data, command_output, json_output),
None => println!("Process terminated by signal")
}
});
handles.push(child);
}
for handle in handles { handle.join().unwrap(); }
let serializable_output = SerializableOutput { tasks: *outputs.unwrap() };
println!("{}", serde_json::to_string(&serializable_output));
if json_output == true {
let slice = &*outputs.lock().unwrap();
let serializable_output = SerializableOutput { tasks: slice.to_vec() };
println!("{}", serde_json::to_string(&serializable_output).unwrap());
}
true
}

0 comments on commit dc21174

Please sign in to comment.