From 3f6cf8ea62e8712d0b6406b0925bf060985e01f3 Mon Sep 17 00:00:00 2001 From: NathanFlurry Date: Sun, 1 Dec 2024 17:25:36 +0000 Subject: [PATCH] chore: don't prompt env selection if there's only one env (#595) Fixes RVT-4232 --- packages/cli/src/commands/environment/select.rs | 2 +- packages/cli/src/util/env.rs | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/commands/environment/select.rs b/packages/cli/src/commands/environment/select.rs index 65647a8a..0fc2d3e0 100644 --- a/packages/cli/src/commands/environment/select.rs +++ b/packages/cli/src/commands/environment/select.rs @@ -7,7 +7,7 @@ pub struct Opts {} impl Opts { pub async fn execute(&self) -> Result<()> { let ctx = toolchain::toolchain_ctx::load().await?; - crate::util::env::select(&ctx).await?; + crate::util::env::select(&ctx, true).await?; Ok(()) } } diff --git a/packages/cli/src/util/env.rs b/packages/cli/src/util/env.rs index 2bb95c29..18358848 100644 --- a/packages/cli/src/util/env.rs +++ b/packages/cli/src/util/env.rs @@ -31,11 +31,13 @@ pub async fn get_or_select( } // Prompt user for selection - select(ctx).await + select(ctx, false).await } /// Select an environment. -pub async fn select(ctx: &toolchain::ToolchainCtx) -> Result { +/// +/// Forcing selection will prompt the user for selection, even if there's only 1 item. +pub async fn select(ctx: &toolchain::ToolchainCtx, force_select: bool) -> Result { // Build selections let mut envs = ctx .project @@ -49,6 +51,12 @@ pub async fn select(ctx: &toolchain::ToolchainCtx) -> Result { .collect::>(); envs.sort_by_key(|e| e.name.clone()); + // If only one env, don't prompt + if !force_select && envs.len() == 1 { + let env = envs.into_iter().next().expect("should have 1 env value"); + return Ok(env.slug); + } + // Choose starting index let start_env_id = meta::try_read_project(&paths::data_dir()?, |p| Ok(p.cloud()?.selected_environment))