diff --git a/crates/cli/src/subcommands/init.rs b/crates/cli/src/subcommands/init.rs index 6ac38f687e1..6825b934cdf 100644 --- a/crates/cli/src/subcommands/init.rs +++ b/crates/cli/src/subcommands/init.rs @@ -181,7 +181,7 @@ pub async fn check_and_prompt_login(config: &mut Config) -> anyhow::Result if should_login { let host = Url::parse(DEFAULT_AUTH_HOST)?; - spacetimedb_login_force(config, &host, false).await?; + spacetimedb_login_force(config, &host, false, true).await?; println!("{}", "Successfully logged in!".green()); Ok(true) } else { diff --git a/crates/cli/src/subcommands/login.rs b/crates/cli/src/subcommands/login.rs index bebd71db2d9..ef696d06a81 100644 --- a/crates/cli/src/subcommands/login.rs +++ b/crates/cli/src/subcommands/login.rs @@ -31,6 +31,12 @@ pub fn cli() -> Command { .group("login-method") .help("Bypass the login flow and use a login token directly"), ) + .arg( + Arg::new("no-browser") + .long("no-browser") + .action(ArgAction::SetTrue) + .help("Do not open a browser window"), + ) .about("Manage your login to the SpacetimeDB CLI") } @@ -54,6 +60,7 @@ pub async fn exec(mut config: Config, args: &ArgMatches) -> Result<(), anyhow::E let host: &String = args.get_one("auth-host").unwrap(); let host = Url::parse(host)?; let server_issued_login: Option<&String> = args.get_one("server"); + let open_browser = !args.get_flag("no-browser"); if let Some(token) = spacetimedb_token { config.set_spacetimedb_token(token.clone()); @@ -63,9 +70,9 @@ pub async fn exec(mut config: Config, args: &ArgMatches) -> Result<(), anyhow::E if let Some(server) = server_issued_login { let host = Url::parse(&config.get_host_url(Some(server))?)?; - spacetimedb_token_cached(&mut config, &host, true).await?; + spacetimedb_token_cached(&mut config, &host, true, open_browser).await?; } else { - spacetimedb_token_cached(&mut config, &host, false).await?; + spacetimedb_token_cached(&mut config, &host, false, open_browser).await?; } Ok(()) @@ -98,7 +105,12 @@ async fn exec_show(config: Config, args: &ArgMatches) -> Result<(), anyhow::Erro Ok(()) } -async fn spacetimedb_token_cached(config: &mut Config, host: &Url, direct_login: bool) -> anyhow::Result { +async fn spacetimedb_token_cached( + config: &mut Config, + host: &Url, + direct_login: bool, + open_browser: bool, +) -> anyhow::Result { // Currently, this token does not expire. However, it will at some point in the future. When that happens, // this code will need to happen before any request to a spacetimedb server, rather than at the end of the login flow here. if let Some(token) = config.spacetimedb_token() { @@ -106,18 +118,23 @@ async fn spacetimedb_token_cached(config: &mut Config, host: &Url, direct_login: println!("If you want to log out, use spacetime logout."); Ok(token.clone()) } else { - spacetimedb_login_force(config, host, direct_login).await + spacetimedb_login_force(config, host, direct_login, open_browser).await } } -pub async fn spacetimedb_login_force(config: &mut Config, host: &Url, direct_login: bool) -> anyhow::Result { +pub async fn spacetimedb_login_force( + config: &mut Config, + host: &Url, + direct_login: bool, + open_browser: bool, +) -> anyhow::Result { let token = if direct_login { let token = spacetimedb_direct_login(host).await?; println!("We have logged in directly to your target server."); println!("WARNING: This login will NOT work for any other servers."); token } else { - let session_token = web_login_cached(config, host).await?; + let session_token = web_login_cached(config, host, open_browser).await?; spacetimedb_login(host, &session_token).await? }; config.set_spacetimedb_token(token.clone()); @@ -126,12 +143,12 @@ pub async fn spacetimedb_login_force(config: &mut Config, host: &Url, direct_log Ok(token) } -async fn web_login_cached(config: &mut Config, host: &Url) -> anyhow::Result { +async fn web_login_cached(config: &mut Config, host: &Url, open_browser: bool) -> anyhow::Result { if let Some(session_token) = config.web_session_token() { // Currently, these session tokens do not expire. At some point in the future, we may also need to check this session token for validity. Ok(session_token.clone()) } else { - let session_token = web_login(host).await?; + let session_token = web_login(host, open_browser).await?; config.set_web_session_token(session_token.clone()); config.save(); Ok(session_token) @@ -193,7 +210,7 @@ impl WebLoginSessionResponse { } } -async fn web_login(remote: &Url) -> Result { +async fn web_login(remote: &Url, open_browser: bool) -> Result { let client = reqwest::Client::new(); let response: WebLoginTokenResponse = client @@ -213,9 +230,13 @@ async fn web_login(remote: &Url) -> Result { browser_url .query_pairs_mut() .append_pair("token", web_login_request_token); - println!("Opening {browser_url} in your browser."); - if webbrowser::open(browser_url.as_str()).is_err() { - println!("Unable to open your browser! Please open the URL above manually."); + if open_browser { + println!("Opening {browser_url} in your browser."); + if webbrowser::open(browser_url.as_str()).is_err() { + println!("Unable to open your browser! Please open the URL above manually."); + } + } else { + println!("Open {browser_url} in your browser to finish logging in."); } println!("Waiting to hear response from the server..."); diff --git a/crates/cli/src/util.rs b/crates/cli/src/util.rs index 2cd09e948ed..b843b9f7aef 100644 --- a/crates/cli/src/util.rs +++ b/crates/cli/src/util.rs @@ -318,10 +318,10 @@ pub async fn get_login_token_or_log_in( if full_login { let host = Url::parse(DEFAULT_AUTH_HOST)?; - spacetimedb_login_force(config, &host, false).await + spacetimedb_login_force(config, &host, false, true).await } else { let host = Url::parse(&config.get_host_url(target_server)?)?; - spacetimedb_login_force(config, &host, true).await + spacetimedb_login_force(config, &host, true, true).await } } diff --git a/docs/docs/00300-resources/00200-reference/00100-cli-reference/00100-cli-reference.md b/docs/docs/00300-resources/00200-reference/00100-cli-reference/00100-cli-reference.md index 508f87a399f..309dd328233 100644 --- a/docs/docs/00300-resources/00200-reference/00100-cli-reference/00100-cli-reference.md +++ b/docs/docs/00300-resources/00200-reference/00100-cli-reference/00100-cli-reference.md @@ -378,6 +378,7 @@ Manage your login to the SpacetimeDB CLI Default value: `https://spacetimedb.com` * `--server-issued-login ` — Log in to a SpacetimeDB server directly, without going through a global auth server * `--token ` — Bypass the login flow and use a login token directly +* `--no-browser` — Do not open a browser window diff --git a/tools/xtask-llm-benchmark/src/benchmarks/schema/t_016_sum_type_columns/spec.rs b/tools/xtask-llm-benchmark/src/benchmarks/schema/t_016_sum_type_columns/spec.rs index 6b335621c0a..fe09e6656f9 100644 --- a/tools/xtask-llm-benchmark/src/benchmarks/schema/t_016_sum_type_columns/spec.rs +++ b/tools/xtask-llm-benchmark/src/benchmarks/schema/t_016_sum_type_columns/spec.rs @@ -1,7 +1,5 @@ use crate::eval::defaults::{ - default_schema_parity_scorers, - make_reducer_data_parity_scorer, - make_sql_count_only_scorer, + default_schema_parity_scorers, make_reducer_data_parity_scorer, make_sql_count_only_scorer, }; use crate::eval::{casing_for_lang, ident, BenchmarkSpec, ReducerDataParityConfig, SqlBuilder}; use std::time::Duration; @@ -13,18 +11,21 @@ pub fn spec() -> BenchmarkSpec { let sb = SqlBuilder::new(casing); let reducer = ident("Seed", casing); - let select = sb.select_by_id("drawing", &["id","a","b"], "id", 1); + let select = sb.select_by_id("drawing", &["id", "a", "b"], "id", 1); - v.push(make_reducer_data_parity_scorer(host_url, ReducerDataParityConfig { - src_file: file!(), - route_tag, - reducer: reducer.into(), - args: vec![], - select_query: select.clone(), - id_str: "sum_type_columns_row_parity", - collapse_ws: true, - timeout: Duration::from_secs(10), - })); + v.push(make_reducer_data_parity_scorer( + host_url, + ReducerDataParityConfig { + src_file: file!(), + route_tag, + reducer: reducer.into(), + args: vec![], + select_query: select.clone(), + id_str: "sum_type_columns_row_parity", + collapse_ws: true, + timeout: Duration::from_secs(10), + }, + )); let count = sb.count_by_id("drawing", "id", 1); v.push(make_sql_count_only_scorer(