mgt 0.0.1

Command line tool to analyze the WildFly management model.
//! Lists all supported WildFly versions.

use comfy_table::presets::UTF8_BORDERS_ONLY;
use comfy_table::{Cell, Color, ContentArrangement, Table};
use wildfly_container_versions::VERSIONS;

/// Prints a table of all supported WildFly versions with their metadata.
pub fn versions() {
    let mut table = Table::new();
    table
        .load_preset(UTF8_BORDERS_ONLY)
        .set_content_arrangement(ContentArrangement::Dynamic)
        .set_header(vec![
            "Version",
            "Full Version",
            "WildFly Core",
            "Repository",
        ]);

    for wc in VERSIONS.values() {
        table.add_row(vec![
            Cell::new(wc.display_version()).fg(Color::DarkMagenta),
            Cell::new(format!("{}{}", wc.version, suffix_display(&wc.suffix))),
            Cell::new(format!("{}{}", wc.core_version, suffix_display(&wc.suffix))),
            Cell::new(&wc.repository).fg(Color::AnsiValue(248)),
        ]);
    }

    println!("\n{table}");
}

/// Formats a version suffix (e.g. `Final`) with a leading dot, or empty for no suffix.
fn suffix_display(suffix: &str) -> String {
    if suffix.is_empty() {
        String::new()
    } else {
        format!(".{suffix}")
    }
}