pub(crate) fn host_inventory_table(inv: HostInventory, max_width: Option<usize>) -> String {
    let mut table = Table::new();
    table.max_column_width = match max_width {
        Some(n) => n,
        None => 80,
    };
    table.style = TableStyle::blank();
    table.separate_rows = false;

    table.add_row(Row::new(vec![TableCell::new_with_alignment(
        format!("Host Inventory ({})", inv.host_id),
        4,
        Alignment::Center,
    )]));

    if inv.labels.len() >= 1 {
        table.add_row(Row::new(vec![TableCell::new_with_alignment(
            "",
            4,
            Alignment::Center,
        )]));
        inv.labels.iter().for_each(|(k, v)| {
            table.add_row(Row::new(vec![
                TableCell::new_with_alignment(k, 2, Alignment::Left),
                TableCell::new_with_alignment(v, 2, Alignment::Left),
            ]))
        });
    } else {
        table.add_row(Row::new(vec![TableCell::new_with_alignment(
            "No labels present",
            4,
            Alignment::Center,
        )]));
    }

    if inv.actors.len() >= 1 {
        table.add_row(Row::new(vec![TableCell::new_with_alignment(
            "",
            4,
            Alignment::Center,
        )]));
        table.add_row(Row::new(vec![
            TableCell::new_with_alignment("Actor ID", 2, Alignment::Left),
            TableCell::new_with_alignment("Image Reference", 2, Alignment::Left),
        ]));
        inv.actors.iter().for_each(|a| {
            let a = a.clone();
            table.add_row(Row::new(vec![
                TableCell::new_with_alignment(a.id, 2, Alignment::Left),
                TableCell::new_with_alignment(
                    a.image_ref.unwrap_or("N/A".to_string()),
                    2,
                    Alignment::Left,
                ),
            ]))
        });
    } else {
        table.add_row(Row::new(vec![TableCell::new_with_alignment(
            "No actors found",
            4,
            Alignment::Center,
        )]));
    }

    if inv.providers.len() >= 1 {
        table.add_row(Row::new(vec![TableCell::new_with_alignment(
            "",
            4,
            Alignment::Center,
        )]));
        table.add_row(Row::new(vec![
            TableCell::new_with_alignment("Provider ID", 2, Alignment::Left),
            TableCell::new_with_alignment("Link Name", 1, Alignment::Left),
            TableCell::new_with_alignment("Image Reference", 1, Alignment::Left),
        ]));
        inv.providers.iter().for_each(|p| {
            let p = p.clone();
            table.add_row(Row::new(vec![
                TableCell::new_with_alignment(p.id, 2, Alignment::Left),
                TableCell::new_with_alignment(p.link_name, 1, Alignment::Left),
                TableCell::new_with_alignment(
                    p.image_ref.unwrap_or("N/A".to_string()),
                    1,
                    Alignment::Left,
                ),
            ]))
        });
    } else {
        table.add_row(Row::new(vec![TableCell::new_with_alignment(
            "No providers found",
            4,
            Alignment::Left,
        )]));
    }

    table.render()
}
/// Helper function to print a HostInventory to stdout as a table
Helper function to print a HostInventory to stdout as a table
Helper function to print a HostInventory to stdout as a table
pub(crate) fn host_inventory_table(inv: HostInventory, max_width: Option<usize>) -> String {
    let mut table = Table::new();
    table.max_column_width = match max_width {
        Some(n) => n,
        None => 80,
    };
    table.style = TableStyle::blank();
    table.separate_rows = false;
    table.add_row(Row::new(vec![TableCell::new_with_alignment(
        format!("Host Inventory ({})", inv.host_id),
        4,
        Alignment::Center,
    )]));
    if inv.labels.len() >= 1 {
        table.add_row(Row::new(vec![TableCell::new_with_alignment(
            "",
            4,
            Alignment::Center,
        )]));
        inv.labels.iter().for_each(|(k, v)| {
            table.add_row(Row::new(vec![
                TableCell::new_with_alignment(k, 2, Alignment::Left),
                TableCell::new_with_alignment(v, 2, Alignment::Left),
            ]))
        });
    } else {
        table.add_row(Row::new(vec![TableCell::new_with_alignment(
            "No labels present",
            4,
            Alignment::Center,
        )]));
    }
    if inv.actors.len() >= 1 {
        table.add_row(Row::new(vec![TableCell::new_with_alignment(
            "",
            4,
            Alignment::Center,
        )]));
        table.add_row(Row::new(vec![
            TableCell::new_with_alignment("Actor ID", 2, Alignment::Left),
            TableCell::new_with_alignment("Image Reference", 2, Alignment::Left),
        ]));
        inv.actors.iter().for_each(|a| {
            let a = a.clone();
            table.add_row(Row::new(vec![
                TableCell::new_with_alignment(a.id, 2, Alignment::Left),
                TableCell::new_with_alignment(
                    a.image_ref.unwrap_or("N/A".to_string()),
                    2,
                    Alignment::Left,
                ),
            ]))
        });
    } else {
        table.add_row(Row::new(vec![TableCell::new_with_alignment(
            "No actors found",
            4,
            Alignment::Center,
        )]));
    }
    if inv.providers.len() >= 1 {
        table.add_row(Row::new(vec![TableCell::new_with_alignment(
            "",
            4,
            Alignment::Center,
        )]));
        table.add_row(Row::new(vec![
            TableCell::new_with_alignment("Provider ID", 2, Alignment::Left),
            TableCell::new_with_alignment("Link Name", 1, Alignment::Left),
            TableCell::new_with_alignment("Image Reference", 1, Alignment::Left),
        ]));
        inv.providers.iter().for_each(|p| {
            let p = p.clone();
            table.add_row(Row::new(vec![
                TableCell::new_with_alignment(p.id, 2, Alignment::Left),
                TableCell::new_with_alignment(p.link_name, 1, Alignment::Left),
                TableCell::new_with_alignment(
                    p.image_ref.unwrap_or("N/A".to_string()),
                    1,
                    Alignment::Left,
                ),
            ]))
        });
    } else {
        table.add_row(Row::new(vec![TableCell::new_with_alignment(
            "No providers found",
            4,
            Alignment::Left,
        )]));
    }
    table.render()
}
pub ( crate ) fn host_inventory_table ( inv : HostInventory , max_width : Option < usize > ) -> String { let mut table = Table :: new ( ) ; table . max_column_width = match max_width { Some ( n ) => n , None => 80 , } ; table . style = TableStyle :: blank ( ) ; table . separate_rows = false ; table . add_row ( Row :: new ( vec ! [ TableCell new_with_alignment ( format ( " " inv host_id ) 4 Alignment Center ) ] ) ) ; if inv . labels . len ( ) >= 1 { table . add_row ( Row :: new ( vec ! [ TableCell new_with_alignment ( " " 4 Alignment Center ) ] ) ) ; inv . labels . iter ( ) . for_each ( | ( k , v ) | { table . add_row ( Row :: new ( vec ! [ TableCell new_with_alignment ( k 2 Alignment Left ) TableCell new_with_alignment ( v 2 Alignment Left ) ] ) ) } ) ; } else { table . add_row ( Row :: new ( vec ! [ TableCell new_with_alignment ( " " 4 Alignment Center ) ] ) ) ; } if inv . actors . len ( ) >= 1 { table . add_row ( Row :: new ( vec ! [ TableCell new_with_alignment ( " " 4 Alignment Center ) ] ) ) ; table . add_row ( Row :: new ( vec ! [ TableCell new_with_alignment ( " " 2 Alignment Left ) TableCell new_with_alignment ( " " 2 Alignment Left ) ] ) ) ; inv . actors . iter ( ) . for_each ( | a | { let a = a . clone ( ) ; table . add_row ( Row :: new ( vec ! [ TableCell new_with_alignment ( a id 2 Alignment Left ) TableCell new_with_alignment ( a image_ref unwrap_or ( " " to_string ( ) ) 2 Alignment Left ) ] ) ) } ) ; } else { table . add_row ( Row :: new ( vec ! [ TableCell new_with_alignment ( " " 4 Alignment Center ) ] ) ) ; } if inv . providers . len ( ) >= 1 { table . add_row ( Row :: new ( vec ! [ TableCell new_with_alignment ( " " 4 Alignment Center ) ] ) ) ; table . add_row ( Row :: new ( vec ! [ TableCell new_with_alignment ( " " 2 Alignment Left ) TableCell new_with_alignment ( " " 1 Alignment Left ) TableCell new_with_alignment ( " " 1 Alignment Left ) ] ) ) ; inv . providers . iter ( ) . for_each ( | p | { let p = p . clone ( ) ; table . add_row ( Row :: new ( vec ! [ TableCell new_with_alignment ( p id 2 Alignment Left ) TableCell new_with_alignment ( p link_name 1 Alignment Left ) TableCell new_with_alignment ( p image_ref unwrap_or ( " " to_string ( ) ) 1 Alignment Left ) ] ) ) } ) ; } else { table . add_row ( Row :: new ( vec ! [ TableCell new_with_alignment ( " " 4 Alignment Left ) ] ) ) ; } table . render ( ) }
Helper function to print a HostInventory to stdout as a table
Helper function to print a HostInventory to stdout as a table
inv
HostInventory
max_width
Option<usize>
inv
HostInventory
max_width
Option<usize>