multiversx_sc_meta/cmd/
print_util.rs

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
72
73
74
75
76
77
78
79
use colored::Colorize;
use multiversx_sc_meta_lib::{cargo_toml::DependencyReference, version::FrameworkVersion};
use std::path::Path;

use crate::folder_structure::{DirectoryType, RelevantDirectory};

pub fn print_all_count(num_contract_crates: usize) {
    println!(
        "\n{}",
        format!("Found {num_contract_crates} contract crates.").truecolor(128, 128, 128),
    );
}

pub fn print_all_index(contract_crates_index: usize, num_contract_crates: usize) {
    println!(
        "\n{}",
        format!("({contract_crates_index}/{num_contract_crates})").truecolor(128, 128, 128),
    );
}

pub fn print_all_command(meta_path: &Path, cargo_run_args: &[String]) {
    println!(
        "{} {}\n{} `cargo {}`",
        "In".green(),
        meta_path.display(),
        "Calling".green(),
        cargo_run_args.join(" "),
    );
}

pub fn print_tree_dir_metadata(dir: &RelevantDirectory, last_version: &FrameworkVersion) {
    match dir.dir_type {
        DirectoryType::Contract => print!(" {}", "[contract]".blue()),
        DirectoryType::Lib => print!(" {}", "[lib]".magenta()),
    }

    match &dir.version {
        DependencyReference::Version(version_req) => {
            let version_string = format!("[{}]", version_req.semver);
            if version_req.semver == *last_version {
                print!(" {}", version_string.green());
            } else {
                print!(" {}", version_string.red());
            };
        },
        DependencyReference::GitCommit(git_reference) => {
            let git_string = format!(
                "[git: {} rev: {}]",
                git_reference.git.truecolor(255, 127, 0),
                git_reference.rev.truecolor(255, 127, 0)
            );
            print!(" {}", git_string.truecolor(255, 198, 0));
        },
        DependencyReference::GitBranch(git_reference) => {
            let git_string = format!(
                "[git: {} branch: {}]",
                git_reference.git.truecolor(255, 127, 0),
                git_reference.branch.truecolor(255, 127, 0)
            );
            print!(" {}", git_string.truecolor(255, 198, 0));
        },
        DependencyReference::GitTag(git_reference) => {
            let git_string = format!(
                "[git: {} rev: {}]",
                git_reference.git.truecolor(255, 127, 0),
                git_reference.tag.truecolor(255, 127, 0)
            );
            print!(" {}", git_string.truecolor(255, 198, 0));
        },
        DependencyReference::Path(path_buf) => {
            let git_string = format!("[path: {}]", path_buf.truecolor(255, 127, 0));
            print!(" {}", git_string.truecolor(255, 198, 0));
        },
        DependencyReference::Unsupported(error) => {
            let message = format!("dependency error: {error}");
            print!(" {}", message.red());
        },
    }
}