Add test command for progress spinners

This commit is contained in:
Zhaofeng Li 2021-11-16 21:01:33 -08:00
parent 86eeeece3c
commit 7d15d08d6d
3 changed files with 29 additions and 0 deletions

View file

@ -68,6 +68,8 @@ For a sample configuration, see <https://github.com/zhaofengli/colmena>.
// deprecated alias
app = app.subcommand(command::eval::deprecated_alias());
register_command!(test_progress, app);
}
register_command!(apply, app);
@ -96,6 +98,8 @@ pub async fn run() {
// deprecated alias
handle_command!("introspect", eval, matches);
handle_command!("test-progress", test_progress, matches);
if let Some(args) = matches.subcommand_matches("gen-completions") {
return gen_completions(args);
}

View file

@ -5,3 +5,4 @@ pub mod apply_local;
pub mod upload_keys;
pub mod exec;
pub mod nix_info;
pub mod test_progress;

View file

@ -0,0 +1,24 @@
use std::time::Duration;
use clap::{App, AppSettings, SubCommand, ArgMatches};
use tokio::time;
use crate::progress::{Progress, OutputStyle};
pub fn subcommand() -> App<'static, 'static> {
SubCommand::with_name("test-progress")
.about("Run progress spinner tests")
.setting(AppSettings::Hidden)
}
pub async fn run(_global_args: &ArgMatches<'_>, _local_args: &ArgMatches<'_>) {
let progress = Progress::with_style(OutputStyle::Condensed);
let mut task = progress.create_task_progress(String::from("test"));
for i in 0..10 {
time::sleep(Duration::from_secs(2)).await;
task.log(&format!("Very slow counter: {}", i));
}
task.success("Completed");
}