Skip to content

Commit

Permalink
add loading spinner to registry push/pull
Browse files Browse the repository at this point in the history
Signed-off-by: karthik2804 <karthik.ganeshram@fermyon.com>
  • Loading branch information
karthik2804 committed May 10, 2023
1 parent d59fe6f commit d80eec8
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 6 deletions.
34 changes: 34 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ futures = "0.3"
glob = "0.3.1"
hippo-openapi = "0.10"
hippo = { git = "https://github.com/deislabs/hippo-cli", tag = "v0.16.1" }
indicatif = "0.17.3"
is-terminal = "0.4"
lazy_static = "1.4.0"
levenshtein = "1.0.5"
Expand Down
31 changes: 25 additions & 6 deletions src/commands/registry.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::opts::*;
use anyhow::{Context, Result};
use clap::{Parser, Subcommand};
use indicatif::{ProgressBar, ProgressStyle};
use spin_oci::Client;
use std::{io::Read, path::PathBuf};

use crate::opts::*;
use std::{io::Read, path::PathBuf, time::Duration};

/// Commands for working with OCI registries to distribute applications.
#[derive(Subcommand, Debug)]
Expand Down Expand Up @@ -61,10 +61,14 @@ impl Push {
let app = spin_loader::local::from_file(&app_file, Some(dir.path())).await?;

let mut client = spin_oci::Client::new(self.insecure, None).await?;
let digest = client.push(&app, &self.reference).await?;

let _spinner = create_dotted_spinner(2000, "Pushing app to the Registry".to_owned());

let digest = client.push(&app, &self.reference).await?;
match digest {
Some(digest) => println!("Pushed with digest {digest}"),
Some(digest) => {
println!("Pushed with digest {digest}")
}
None => println!("Pushed; the registry did not return the digest"),
};

Expand Down Expand Up @@ -92,8 +96,11 @@ impl Pull {
/// Pull a Spin application from an OCI registry
pub async fn run(self) -> Result<()> {
let mut client = spin_oci::Client::new(self.insecure, None).await?;
client.pull(&self.reference).await?;

let _spinner = create_dotted_spinner(2000, "Pulling app from the Registry".to_owned());

client.pull(&self.reference).await?;
println!("Successfully pulled the app from the registry");
Ok(())
}
}
Expand Down Expand Up @@ -165,3 +172,15 @@ impl Login {
Ok(())
}
}

fn create_dotted_spinner(interval: u64, message: String) -> ProgressBar {
let spinner = ProgressBar::new_spinner();
spinner.enable_steady_tick(Duration::from_millis(interval));
spinner.set_style(
ProgressStyle::with_template("{msg}{spinner}")
.unwrap()
.tick_strings(&[".", "..", "...", "....", "....."]),
);
spinner.set_message(message);
spinner
}

0 comments on commit d80eec8

Please sign in to comment.