From 5ee29ca1723b7397c9b2897f3ed64c99bfb363ef Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Tue, 17 Oct 2023 09:23:35 -0700 Subject: [PATCH] fh status: friendlier error message when logged out --- src/cli/cmd/status/mod.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/cli/cmd/status/mod.rs b/src/cli/cmd/status/mod.rs index 5c16393e..03584a97 100644 --- a/src/cli/cmd/status/mod.rs +++ b/src/cli/cmd/status/mod.rs @@ -51,8 +51,19 @@ where #[async_trait::async_trait] impl CommandExecute for StatusSubcommand { async fn execute(self) -> color_eyre::Result { - let status = get_status_from_auth_file(self.api_addr).await?; - print!("{status}"); + match get_status_from_auth_file(self.api_addr).await { + Ok(status) => { + print!("{status}"); + } + Err(_) => { + print!( + "\ + Logged in: false\n\ + To log in, run `fh login`.\n\ + " + ); + } + }; Ok(ExitCode::SUCCESS) } @@ -64,12 +75,7 @@ pub(crate) async fn get_status_from_auth_file( let auth_token_path = crate::cli::cmd::login::auth_token_path()?; let token = tokio::fs::read_to_string(&auth_token_path) .await - .wrap_err_with(|| { - format!( - "Could not open {}; have you run `fh login`?", - auth_token_path.display() - ) - })?; + .wrap_err_with(|| format!("Could not open {}", auth_token_path.display()))?; let token = token.trim(); get_status_from_auth_token(api_addr, token).await