Skip to content

Commit

Permalink
feat: added progress indicator at the start of create
Browse files Browse the repository at this point in the history
  • Loading branch information
chiragbhatia8 committed Apr 12, 2023
1 parent b5e4857 commit 58ce7a4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions eksup/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ aws-sdk-autoscaling = "0.25"
aws-sdk-ec2 = "0.25"
aws-sdk-eks = "0.25"
aws-types = "0.55"
indicatif = "0.16.2"
clap = { version = "4.0", features = ["derive", "string"] }
clap-verbosity-flag = "2.0"
handlebars = { version = "4.3", features = ["rust-embed"] }
Expand Down
7 changes: 7 additions & 0 deletions eksup/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod k8s;
mod output;
mod playbook;
mod version;
mod progress;

use std::{env, process, str};

Expand Down Expand Up @@ -98,6 +99,7 @@ pub async fn analyze(args: &Analysis) -> Result<()> {
// All checks and validations on input should happen above/before running the analysis
let results = analysis::analyze(&aws_config, &cluster).await?;
output::output(&results, &args.format, &args.output).await?;
progress_tracker.set_progress(75);

Ok(())
}
Expand All @@ -118,6 +120,8 @@ async fn get_config(region: &Option<String>) -> Result<aws_config::SdkConfig> {
pub async fn create(args: &Create) -> Result<()> {
match &args.command {
CreateCommands::Playbook(playbook) => {
// start the progress tracker
let progress_tracker = ProgressTracker::new();
// Query Kubernetes first so that we can get AWS details that require them
let aws_config = get_config(&playbook.region.to_owned()).await?;
let region = aws_config.region().unwrap().to_string();
Expand All @@ -132,12 +136,15 @@ pub async fn create(args: &Create) -> Result<()> {
return Ok(());
}

progress_tracker.set_progress(25);
let results = analysis::analyze(&aws_config, &cluster).await?;
progress_tracker.set_progress(50);

if let Err(err) = playbook::create(playbook, region, &cluster, results) {
eprintln!("{err}");
process::exit(2);
}
progress_tracker.finish();
}
}

Expand Down
24 changes: 24 additions & 0 deletions eksup/src/progress.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use indicatif::{ProgressBar, ProgressStyle};

pub struct ProgressTracker {
progress_bar: ProgressBar,
}

impl ProgressTracker {
pub fn new() -> Self {
let progress_bar = ProgressBar::new(100);
progress_bar.set_style(ProgressStyle::default_bar()
.template("{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {percent}% ({eta})")
.progress_chars("=> "));

Self { progress_bar }
}

pub fn set_progress(&self, progress: u8) {
self.progress_bar.set_position(progress as u64);
}

pub fn finish(&self) {
self.progress_bar.finish();
}
}

0 comments on commit 58ce7a4

Please sign in to comment.