From 141ebf0cc0c6cfea640debc9b9073303509a8bc7 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Tue, 20 Feb 2024 16:22:10 +0000 Subject: feat(list): set checkout branch as default choice instead of no default. note: I spent hours trying to get CliTester to support default choices and gave up. I have a stashed the attempt and am moving on... --- src/cli_interactor.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/cli_interactor.rs') diff --git a/src/cli_interactor.rs b/src/cli_interactor.rs index a702a54..dc15c87 100644 --- a/src/cli_interactor.rs +++ b/src/cli_interactor.rs @@ -41,12 +41,17 @@ impl InteractorPrompt for Interactor { Ok(confirm) } fn choice(&self, parms: PromptChoiceParms) -> Result { - dialoguer::Select::with_theme(&self.theme) + let mut choice = dialoguer::Select::with_theme(&self.theme); + choice .with_prompt(parms.prompt) .report(parms.report) - .items(&parms.choices) - .interact() - .context("failed to get choice") + .items(&parms.choices); + if let Some(default) = parms.default { + if std::env::var("NGITTEST").is_err() { + choice.default(default); + } + } + choice.interact().context("failed to get choice") } } @@ -110,6 +115,7 @@ impl PromptConfirmParms { pub struct PromptChoiceParms { pub prompt: String, pub choices: Vec, + pub default: Option, pub report: bool, } @@ -128,4 +134,9 @@ impl PromptChoiceParms { self.choices = choices; self } + + pub fn with_default(mut self, index: usize) -> Self { + self.default = Some(index); + self + } } -- cgit v1.2.3