aboutsummaryrefslogtreecommitdiff
path: root/dev/ci/src/cmd/cmd_show_manifests.rs
blob: 2be82d23a370a8a95d4522609a67ba03bd7444fa (plain) (blame)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use std::path::PathBuf;

use mingling::{
    Grouped,
    macros::{buffer, command, r_println, renderer},
};

use prettytable::{
    Cell, Row, Table,
    format::{FormatBuilder, LinePosition, LineSeparator},
};

use crate::res::Manifests;

#[command(node = "show-manifests")]
pub fn show_manifests(manifests: &Manifests) -> ResultPrintManifests {
    let mut entries: Vec<ManifestEntry> = manifests
        .package_dirs
        .iter()
        .map(|(name, path)| ManifestEntry {
            name: name.clone(),
            path: path.clone(),
        })
        .collect();
    entries.sort_by(|a, b| a.path.cmp(&b.path));
    ResultPrintManifests { entries }
}

/// All manifests the CI will check, sorted by path.
#[derive(Grouped)]
pub struct ResultPrintManifests {
    pub entries: Vec<ManifestEntry>,
}

#[derive(Debug, Clone)]
pub struct ManifestEntry {
    pub name: String,
    pub path: PathBuf,
}

#[renderer(buffer)]
pub fn render_print_manifests(r: ResultPrintManifests) {
    let mut table = Table::new();

    table.set_format(
        FormatBuilder::new()
            .column_separator('│')
            .borders('│')
            .separator(LinePosition::Top, LineSeparator::new('─', '┬', '┌', '┐'))
            .separator(LinePosition::Title, LineSeparator::new('─', '┼', '├', '┤'))
            .separator(LinePosition::Bottom, LineSeparator::new('─', '┴', '└', '┘'))
            .padding(1, 1)
            .build(),
    );

    table.set_titles(Row::new(vec![
        Cell::new("#"),
        Cell::new("Package-Name"),
        Cell::new("Package-Path"),
    ]));

    for (index, entry) in r.entries.iter().enumerate() {
        table.add_row(Row::new(vec![
            Cell::new(&(index + 1).to_string()),
            Cell::new(&entry.name),
            Cell::new(&entry.path.to_string_lossy()),
        ]));
    }

    r_println!("{table}");
}