diff --git a/crates/q_cli/src/cli/mod.rs b/crates/q_cli/src/cli/mod.rs index eff11a326f..4e6e50a65c 100644 --- a/crates/q_cli/src/cli/mod.rs +++ b/crates/q_cli/src/cli/mod.rs @@ -74,11 +74,14 @@ use tracing::{ use self::integrations::IntegrationsSubcommands; use self::user::RootUserSubcommand; -use crate::util::CliContext; use crate::util::desktop::{ LaunchArgs, launch_fig_desktop, }; +use crate::util::{ + CliContext, + assert_logged_in, +}; #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, ValueEnum)] pub enum OutputFormat { @@ -350,6 +353,8 @@ impl Cli { } async fn execute_chat(args: Option>) -> Result { + assert_logged_in().await?; + let secret_store = SecretStore::new().await.ok(); if let Some(secret_store) = secret_store { if let Ok(database) = database() { diff --git a/crates/q_cli/src/cli/user.rs b/crates/q_cli/src/cli/user.rs index 4008f73877..b9b82fd84a 100644 --- a/crates/q_cli/src/cli/user.rs +++ b/crates/q_cli/src/cli/user.rs @@ -59,6 +59,7 @@ use crate::util::spinner::{ SpinnerComponent, }; use crate::util::{ + assert_logged_in, choose, input, }; @@ -198,12 +199,7 @@ impl RootUserSubcommand { } }, Self::Profile => { - if !fig_util::system_info::in_cloudshell() && !fig_auth::is_logged_in().await { - bail!( - "You are not logged in, please log in with {}", - format!("{CLI_BINARY_NAME} login",).bold() - ); - } + assert_logged_in().await?; if let Ok(Some(token)) = fig_auth::builder_id_token().await { if matches!(token.token_type(), TokenType::BuilderId) { diff --git a/crates/q_cli/src/util/mod.rs b/crates/q_cli/src/util/mod.rs index 9fea5a9c52..57fe46e482 100644 --- a/crates/q_cli/src/util/mod.rs +++ b/crates/q_cli/src/util/mod.rs @@ -32,6 +32,7 @@ use dialoguer::theme::ColorfulTheme; use eyre::{ Context, ContextCompat, + Error, Result, bail, }; @@ -289,6 +290,17 @@ pub fn dialoguer_theme() -> ColorfulTheme { } } +pub async fn assert_logged_in() -> Result<(), Error> { + if !fig_util::system_info::in_cloudshell() && !fig_auth::is_logged_in().await { + bail!( + "You are not logged in, please log in with {}", + format!("{CLI_BINARY_NAME} login",).bold() + ); + } + + Ok(()) +} + #[cfg(target_os = "macos")] pub async fn is_brew_reinstall() -> bool { let regex = regex::bytes::Regex::new(r"brew(\.\w+)?\s+(upgrade|reinstall|install)").unwrap();