fn print_servicelist(
    servlist: ServiceList,
    regex: Option<Regex>,
    _show_labels: bool,
    writer: &mut ClickWriter,
) -> ServiceList {
    let mut table = Table::new();
    table.set_titles(row![
        "####",
        "Name",
        "ClusterIP",
        "External IPs",
        "Port(s)",
        "Age"
    ]);
    let service_specs = servlist.items.into_iter().map(|service| {
        let mut specs = Vec::new();

        specs.push(CellSpec::new_index());

        specs.push(CellSpec::new_owned(service.metadata.name.clone()));
        specs.push(CellSpec::new_owned(format!(
            "{}",
            service
                .spec
                .cluster_ip
                .as_ref()
                .unwrap_or(&"<none>".to_owned())
        )));
        if let Some(ref eips) = service.spec.external_ips {
            specs.push(CellSpec::new_owned(shorten_to(eips.join(", "), 18)));
        } else {
            // look in the status for the elb name
            if let Some(ing_val) = service.status.pointer("/loadBalancer/ingress") {
                if let Some(ing_arry) = ing_val.as_array() {
                    let strs: Vec<&str> = ing_arry
                        .iter()
                        .map(|v| {
                            if let Some(hv) = v.get("hostname") {
                                hv.as_str().unwrap_or("")
                            } else if let Some(ipv) = v.get("ip") {
                                ipv.as_str().unwrap_or("")
                            } else {
                                ""
                            }
                        })
                        .collect();
                    let s = strs.join(", ");
                    specs.push(CellSpec::new_owned(shorten_to(s, 18)));
                } else {
                    specs.push(CellSpec::new("<none>"));
                }
            } else {
                specs.push(CellSpec::new("<none>"));
            }
        }

        let port_strs: Vec<String> = if let Some(ref ports) = service.spec.ports {
            ports
                .iter()
                .map(|p| {
                    if let Some(np) = p.node_port {
                        format!("{}:{}/{}", p.port, np, p.protocol)
                    } else {
                        format!("{}/{}", p.port, p.protocol)
                    }
                })
                .collect()
        } else {
            vec!["<none>".to_owned()]
        };
        specs.push(CellSpec::new_owned(port_strs.join(",")));
        specs.push(CellSpec::new_owned(format!(
            "{}",
            time_since(service.metadata.creation_timestamp.unwrap())
        )));

        (service, specs)
    });

    let filtered = match regex {
        Some(r) => ::table::filter(service_specs, r),
        None => service_specs.collect(),
    };

    ::table::print_table(&mut table, &filtered, writer);

    let final_services = filtered
        .into_iter()
        .map(|service_spec| service_spec.0)
        .collect();
    ServiceList {
        items: final_services,
    }
}
/// Print out the specified list of deployments in a pretty format
Print out the specified list of deployments in a pretty format
Print out the specified list of deployments in a pretty format
fn print_servicelist(
    servlist: ServiceList,
    regex: Option<Regex>,
    _show_labels: bool,
    writer: &mut ClickWriter,
) -> ServiceList {
    let mut table = Table::new();
    table.set_titles(row![
        "####",
        "Name",
        "ClusterIP",
        "External IPs",
        "Port(s)",
        "Age"
    ]);
    let service_specs = servlist.items.into_iter().map(|service| {
        let mut specs = Vec::new();
        specs.push(CellSpec::new_index());
        specs.push(CellSpec::new_owned(service.metadata.name.clone()));
        specs.push(CellSpec::new_owned(format!(
            "{}",
            service
                .spec
                .cluster_ip
                .as_ref()
                .unwrap_or(&"<none>".to_owned())
        )));
        if let Some(ref eips) = service.spec.external_ips {
            specs.push(CellSpec::new_owned(shorten_to(eips.join(", "), 18)));
        } else {
            // look in the status for the elb name
            if let Some(ing_val) = service.status.pointer("/loadBalancer/ingress") {
                if let Some(ing_arry) = ing_val.as_array() {
                    let strs: Vec<&str> = ing_arry
                        .iter()
                        .map(|v| {
                            if let Some(hv) = v.get("hostname") {
                                hv.as_str().unwrap_or("")
                            } else if let Some(ipv) = v.get("ip") {
                                ipv.as_str().unwrap_or("")
                            } else {
                                ""
                            }
                        })
                        .collect();
                    let s = strs.join(", ");
                    specs.push(CellSpec::new_owned(shorten_to(s, 18)));
                } else {
                    specs.push(CellSpec::new("<none>"));
                }
            } else {
                specs.push(CellSpec::new("<none>"));
            }
        }
        let port_strs: Vec<String> = if let Some(ref ports) = service.spec.ports {
            ports
                .iter()
                .map(|p| {
                    if let Some(np) = p.node_port {
                        format!("{}:{}/{}", p.port, np, p.protocol)
                    } else {
                        format!("{}/{}", p.port, p.protocol)
                    }
                })
                .collect()
        } else {
            vec!["<none>".to_owned()]
        };
        specs.push(CellSpec::new_owned(port_strs.join(",")));
        specs.push(CellSpec::new_owned(format!(
            "{}",
            time_since(service.metadata.creation_timestamp.unwrap())
        )));
        (service, specs)
    });
    let filtered = match regex {
        Some(r) => ::table::filter(service_specs, r),
        None => service_specs.collect(),
    };
    ::table::print_table(&mut table, &filtered, writer);
    let final_services = filtered
        .into_iter()
        .map(|service_spec| service_spec.0)
        .collect();
    ServiceList {
        items: final_services,
    }
}
fn print_servicelist ( servlist : ServiceList , regex : Option < Regex > , _show_labels : bool , writer : & mut ClickWriter , ) -> ServiceList { let mut table = Table :: new ( ) ; table . set_titles ( row ! [ " " " " " " " " " " " " ] ) ; let service_specs = servlist . items . into_iter ( ) . map ( | service | { let mut specs = Vec :: new ( ) ; specs . push ( CellSpec :: new_index ( ) ) ; specs . push ( CellSpec :: new_owned ( service . metadata . name . clone ( ) ) ) ; specs . push ( CellSpec :: new_owned ( format ! ( " " service spec cluster_ip as_ref ( ) unwrap_or ( " " to_owned ( ) ) ) ) ) ; if let Some ( ref eips ) = service . spec . external_ips { specs . push ( CellSpec :: new_owned ( shorten_to ( eips . join ( " " ) , 18 ) ) ) ; } else { // look in the status for the elb name if let Some ( ing_val ) = service . status . pointer ( " " ) { if let Some ( ing_arry ) = ing_val . as_array ( ) { let strs : Vec < & str > = ing_arry . iter ( ) . map ( | v | { if let Some ( hv ) = v . get ( " " ) { hv . as_str ( ) . unwrap_or ( " " ) } else if let Some ( ipv ) = v . get ( " " ) { ipv . as_str ( ) . unwrap_or ( " " ) } else { " " } } ) . collect ( ) ; let s = strs . join ( " " ) ; specs . push ( CellSpec :: new_owned ( shorten_to ( s , 18 ) ) ) ; } else { specs . push ( CellSpec :: new ( " " ) ) ; } } else { specs . push ( CellSpec :: new ( " " ) ) ; } } let port_strs : Vec < String > = if let Some ( ref ports ) = service . spec . ports { ports . iter ( ) . map ( | p | { if let Some ( np ) = p . node_port { format ! ( " " p port np p protocol ) } else { format ! ( " " p port p protocol ) } } ) . collect ( ) } else { vec ! [ " " to_owned ( ) ] } ; specs . push ( CellSpec :: new_owned ( port_strs . join ( " " ) ) ) ; specs . push ( CellSpec :: new_owned ( format ! ( " " time_since ( service metadata creation_timestamp unwrap ( ) ) ) ) ) ; ( service , specs ) } ) ; let filtered = match regex { Some ( r ) => :: table :: filter ( service_specs , r ) , None => service_specs . collect ( ) , } ; :: table :: print_table ( & mut table , & filtered , writer ) ; let final_services = filtered . into_iter ( ) . map ( | service_spec | service_spec . 0 ) . collect ( ) ; ServiceList { items : final_services , } }
Print out the specified list of deployments in a pretty format
Print out the specified list of deployments in a pretty format
servlist
ServiceList
regex
Option<Regex>
_show_labels
bool
writer
&mut ClickWriter
servlist
ServiceList
regex
Option<Regex>
_show_labels
bool
writer
&mut ClickWriter