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
30
31
32
use aws_codebuild_status_derive::{BuildInformation, CodebuildOutput};
use colored::Colorize;
use prettytable::{cell, row, Table};
use std::collections::HashMap;

pub struct TerminalOutput;

impl CodebuildOutput for TerminalOutput {

    fn print(build_info: HashMap<String, Vec<BuildInformation>>) {
        let mut table = Table::new();
        table.add_row(row!["#", "Project name", "Status", "Branch", "Finished"]);

        for (i, (_, builds)) in build_info.iter().enumerate() {

            for build in builds {
                let status = match build.status.as_ref() {
                    "SUCCEEDED" => "SUCCEEDED".green(),
                    "IN_PROGRESS" => "IN_PROGRESS".yellow(),
                    "FAILED" => "FAILED".red(),
                    "TIMED_OUT" => "TIMED_OUT".red(),
                    "STOPPED" => "STOPPED".red(),
                    _ => "UNDEFINED".red(),
                };

                table.add_row(row![i, build.name, status, build.branch, build.timestamp]);
            }
        }

        table.printstd();
    }
}