diff --git a/Cargo.lock b/Cargo.lock index 1f46b76c07..4b79b3b15b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2500,6 +2500,18 @@ dependencies = [ "serde", ] +[[package]] +name = "indicatif" +version = "0.17.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cef509aa9bc73864d6756f0d34d35504af3cf0844373afe9b8669a5b8005a729" +dependencies = [ + "console", + "number_prefix", + "portable-atomic 0.3.20", + "unicode-width", +] + [[package]] name = "inotify" version = "0.9.6" @@ -3327,6 +3339,12 @@ dependencies = [ "libc", ] +[[package]] +name = "number_prefix" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" + [[package]] name = "oauth2" version = "4.3.0" @@ -3798,6 +3816,21 @@ dependencies = [ "plotters-backend", ] +[[package]] +name = "portable-atomic" +version = "0.3.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e30165d31df606f5726b090ec7592c308a0eaf61721ff64c9a3018e344a8753e" +dependencies = [ + "portable-atomic 1.3.1", +] + +[[package]] +name = "portable-atomic" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bbda379e6e462c97ea6afe9f6233619b202bbc4968d7caa6917788d2070a044" + [[package]] name = "postgres-native-tls" version = "0.5.0" @@ -4961,6 +4994,7 @@ dependencies = [ "hippo", "hippo-openapi", "hyper", + "indicatif", "is-terminal", "lazy_static", "levenshtein", diff --git a/Cargo.toml b/Cargo.toml index 777920b3ec..456c81acd4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/commands/registry.rs b/src/commands/registry.rs index 551b1735db..e5cfcfd8ad 100644 --- a/src/commands/registry.rs +++ b/src/commands/registry.rs @@ -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)] @@ -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"), }; @@ -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(()) } } @@ -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 +}