Skip to content

Commit

Permalink
feat: Simplfy the table generation
Browse files Browse the repository at this point in the history
  • Loading branch information
maheshrayas committed Apr 19, 2022
1 parent d2daf00 commit 2cd4e39
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
14 changes: 11 additions & 3 deletions src/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ use serde_json::Value;
use std::sync::Arc;
use tokio::task::spawn;

pub(crate) async fn get_cluster_resources(version: &str, val: Vec<Value>) -> Result<ClusterOP> {
pub(crate) async fn get_cluster_resources(
version: &str,
val: Vec<Value>,
) -> Result<Vec<TableDetails>> {
let client = Client::try_default().await?;
let current_config = kube::config::Kubeconfig::read().unwrap();
info!(
"Connected to cluster {:?}",
current_config.current_context.unwrap()
);
info!("Target apiversions v{}", version);
Ok(val
let join_handle: ClusterOP = val
.into_iter()
.map(|resource| {
let arc_client = Arc::new(client.clone());
Expand Down Expand Up @@ -79,5 +82,10 @@ pub(crate) async fn get_cluster_resources(version: &str, val: Vec<Value>) -> Res
Ok(temp_table)
})
})
.collect())
.collect();
let mut v: Vec<TableDetails> = vec![];
for task in join_handle {
v.append(&mut task.await?.unwrap());
}
Ok(v)
}
12 changes: 3 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,12 @@ async fn main() -> anyhow::Result<()> {

match cli.check_scrape_type() {
Scrape::Cluster => {
let join_handle: ClusterOP = get_cluster_resources(version, val).await?;
let x = utils::VecTableDetails(get_cluster_resources(version, val).await?);
match cli.output {
Output::Csv => {
let mut wtr = csv::Writer::from_path("./deprecated-list.csv")?;
generate_csv_header(&mut wtr, "Filename")?;
for task in join_handle {
let x: VecTableDetails = utils::VecTableDetails(task.await?.unwrap());
x.generate_csv(&mut wtr)?;
}
x.generate_csv(&mut wtr)?;
wtr.flush()?;
info!(
"deprecated-list.csv written at location {}",
Expand All @@ -84,10 +81,7 @@ async fn main() -> anyhow::Result<()> {
Output::Table => {
let mut t = Table::new();
let t = generate_table_header(&mut t, "Namespace");
for task in join_handle {
let x: VecTableDetails = utils::VecTableDetails(task.await?.unwrap());
x.generate_table(t)?;
}
x.generate_table(t)?;
println!("{t}");
}
}
Expand Down

0 comments on commit 2cd4e39

Please sign in to comment.