Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added progress indicator at the start of create #1

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 8 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 All @@ -14,6 +15,7 @@ use aws_types::region::Region;
use clap::{Args, Parser, Subcommand};
use clap_verbosity_flag::Verbosity;
use serde::{Deserialize, Serialize};
use progress::ProgressTracker;

#[derive(Parser, Debug)]
#[command(author, about, version)]
Expand Down Expand Up @@ -98,6 +100,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 +121,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 +137,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();
}
}