Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion crates/q_cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -350,6 +353,8 @@ impl Cli {
}

async fn execute_chat(args: Option<Vec<String>>) -> Result<ExitCode> {
assert_logged_in().await?;

let secret_store = SecretStore::new().await.ok();
if let Some(secret_store) = secret_store {
if let Ok(database) = database() {
Expand Down
8 changes: 2 additions & 6 deletions crates/q_cli/src/cli/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ use crate::util::spinner::{
SpinnerComponent,
};
use crate::util::{
assert_logged_in,
choose,
input,
};
Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions crates/q_cli/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use dialoguer::theme::ColorfulTheme;
use eyre::{
Context,
ContextCompat,
Error,
Result,
bail,
};
Expand Down Expand Up @@ -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();
Expand Down
Loading