Skip to content
This repository has been archived by the owner on Dec 21, 2024. It is now read-only.

Commit

Permalink
chore: don't prompt env selection if there's only one env (#595)
Browse files Browse the repository at this point in the history
Fixes RVT-4232
  • Loading branch information
NathanFlurry committed Dec 1, 2024
1 parent a5e4ac6 commit 3f6cf8e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/commands/environment/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}
12 changes: 10 additions & 2 deletions packages/cli/src/util/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
///
/// 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<String> {
// Build selections
let mut envs = ctx
.project
Expand All @@ -49,6 +51,12 @@ pub async fn select(ctx: &toolchain::ToolchainCtx) -> Result<String> {
.collect::<Vec<_>>();
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))
Expand Down

0 comments on commit 3f6cf8e

Please sign in to comment.