diff --git a/src/execute.rs b/src/execute.rs index c1dcab7..c4107c7 100644 --- a/src/execute.rs +++ b/src/execute.rs @@ -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, cwd_path: String, json_output: bool) -> bool { @@ -60,15 +64,18 @@ pub fn run(tasks: Vec, 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 } \ No newline at end of file