|
5 | 5 | // Copyright 2024 Oxide Computer Company |
6 | 6 |
|
7 | 7 | use std::fs::File; |
| 8 | +use std::io::{self, Write}; |
8 | 9 |
|
9 | 10 | use anyhow::{anyhow, bail, Result}; |
10 | 11 | use async_trait::async_trait; |
@@ -237,12 +238,16 @@ impl CmdAuthLogin { |
237 | 238 | }; |
238 | 239 |
|
239 | 240 | if opened { |
240 | | - println!("Opened this URL in your browser:\n {}", uri); |
| 241 | + writeln!(io::stdout(), "Opened this URL in your browser:\n {}", uri)?; |
241 | 242 | } else { |
242 | | - println!("Open this URL in your browser:\n {}", uri); |
| 243 | + writeln!(io::stdout(), "Open this URL in your browser:\n {}", uri)?; |
243 | 244 | } |
244 | 245 |
|
245 | | - println!("\nEnter the code: {}\n", details.user_code().secret()); |
| 246 | + writeln!( |
| 247 | + io::stdout(), |
| 248 | + "\nEnter the code: {}\n", |
| 249 | + details.user_code().secret() |
| 250 | + )?; |
246 | 251 |
|
247 | 252 | let token = auth_client |
248 | 253 | .exchange_device_access_token(&details) |
@@ -357,13 +362,17 @@ impl CmdAuthLogin { |
357 | 362 | silo_name, |
358 | 363 | } = &user; |
359 | 364 |
|
360 | | - println!("Login successful"); |
361 | | - println!(" silo: {} ({})", **silo_name, silo_id); |
362 | | - println!(" user: {} ({})", display_name, id); |
| 365 | + writeln!(io::stdout(), "Login successful")?; |
| 366 | + writeln!(io::stdout(), " silo: {} ({})", **silo_name, silo_id)?; |
| 367 | + writeln!(io::stdout(), " user: {} ({})", display_name, id)?; |
363 | 368 | if ctx.config_file().basics.default_profile.is_none() { |
364 | | - println!("Profile '{}' set as the default", profile_name); |
| 369 | + writeln!( |
| 370 | + io::stdout(), |
| 371 | + "Profile '{}' set as the default", |
| 372 | + profile_name |
| 373 | + )?; |
365 | 374 | } else { |
366 | | - println!("Use --profile '{}'", profile_name); |
| 375 | + writeln!(io::stdout(), "Use --profile '{}'", profile_name)?; |
367 | 376 | } |
368 | 377 |
|
369 | 378 | Ok(()) |
@@ -396,7 +405,7 @@ impl CmdAuthLogout { |
396 | 405 | if self.all { |
397 | 406 | // Clear the entire file for users who want to reset their known hosts. |
398 | 407 | let _ = File::create(credentials_path)?; |
399 | | - println!("Removed all authentication information"); |
| 408 | + writeln!(io::stdout(), "Removed all authentication information")?; |
400 | 409 | } else { |
401 | 410 | let profile = ctx |
402 | 411 | .client_config() |
@@ -424,10 +433,11 @@ impl CmdAuthLogout { |
424 | 433 | }); |
425 | 434 | std::fs::write(credentials_path, credentials.to_string()) |
426 | 435 | .expect("unable to write credentials.toml"); |
427 | | - println!( |
| 436 | + writeln!( |
| 437 | + io::stdout(), |
428 | 438 | "Removed authentication information for profile \"{}\"", |
429 | 439 | profile_name, |
430 | | - ); |
| 440 | + )?; |
431 | 441 | } |
432 | 442 |
|
433 | 443 | Ok(()) |
|
0 commit comments