Skip to content

Commit 65139d0

Browse files
authored
Add progress spinner to auth status subcommand (#748)
When an authenticated Oxide rack is unreachable, e.g. dogfood when the VPN is disabled, `oxide auth status` may take tens of seconds to complete. It is unclear to the user which rack is the source of the delay. Add a progress spinner that shows the rack currently being checked. Closes #567
1 parent f472bce commit 65139d0

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

cli/src/cmd_auth.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ use std::fs::File;
99
use anyhow::{anyhow, bail, Result};
1010
use async_trait::async_trait;
1111
use clap::Parser;
12+
use indicatif::{ProgressBar, ProgressStyle};
1213
use oauth2::{
1314
basic::BasicClient, devicecode::StandardDeviceAuthorizationResponse, AuthType, AuthUrl,
1415
ClientId, DeviceAuthorizationUrl, TokenResponse, TokenUrl,
1516
};
1617
use oxide::types::CurrentUser;
1718
use oxide::{Client, ClientConfig, ClientSessionExt};
19+
use std::time::Duration;
1820
use toml_edit::{Item, Table};
1921
use uuid::Uuid;
2022

@@ -428,6 +430,13 @@ pub struct CmdAuthStatus {}
428430

429431
impl CmdAuthStatus {
430432
pub async fn status(&self, ctx: &Context) -> Result<()> {
433+
let spinner = ProgressBar::new_spinner();
434+
spinner.set_style(
435+
ProgressStyle::default_spinner()
436+
.template("{spinner} {msg}")
437+
.expect("Failed to set spinner template"),
438+
);
439+
431440
// For backward compatibility, we'll check OXIDE_HOST and OXIDE_TOKEN
432441
// first.
433442
if let (Ok(host_env), Ok(token_env)) =
@@ -438,7 +447,13 @@ impl CmdAuthStatus {
438447
)
439448
.expect("client authentication from host/token failed");
440449

441-
match client.current_user_view().send().await {
450+
spinner.set_message(format!("Checking {}...", host_env));
451+
spinner.enable_steady_tick(Duration::from_millis(100));
452+
453+
let result = client.current_user_view().send().await;
454+
spinner.finish();
455+
456+
match result {
442457
Ok(user) => {
443458
log::debug!("success response for {} (env): {:?}", host_env, user);
444459
println_nopipe!("Logged in to {} as {}", host_env, user.id)
@@ -456,7 +471,14 @@ impl CmdAuthStatus {
456471
)
457472
.expect("client authentication from host/token failed");
458473

459-
let status = match client.current_user_view().send().await {
474+
spinner.reset();
475+
spinner.set_message(format!("Checking {}...", &profile_info.host));
476+
spinner.enable_steady_tick(Duration::from_millis(100));
477+
478+
let result = client.current_user_view().send().await;
479+
spinner.finish();
480+
481+
let status = match result {
460482
Ok(v) => {
461483
log::debug!("success response for {}: {:?}", profile_info.host, v);
462484
"Authenticated".to_string()

0 commit comments

Comments
 (0)