diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-02-20 16:22:10 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-02-20 16:48:48 +0000 |
| commit | 141ebf0cc0c6cfea640debc9b9073303509a8bc7 (patch) | |
| tree | 579ef546ea83b13a56066e44c43318ad9ed4f3d0 /src/cli_interactor.rs | |
| parent | c2817d081700d1fe14d92c51c4e89551182e7fb6 (diff) | |
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...
Diffstat (limited to 'src/cli_interactor.rs')
| -rw-r--r-- | src/cli_interactor.rs | 19 |
1 files changed, 15 insertions, 4 deletions
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 { | |||
| 41 | Ok(confirm) | 41 | Ok(confirm) |
| 42 | } | 42 | } |
| 43 | fn choice(&self, parms: PromptChoiceParms) -> Result<usize> { | 43 | fn choice(&self, parms: PromptChoiceParms) -> Result<usize> { |
| 44 | dialoguer::Select::with_theme(&self.theme) | 44 | let mut choice = dialoguer::Select::with_theme(&self.theme); |
| 45 | choice | ||
| 45 | .with_prompt(parms.prompt) | 46 | .with_prompt(parms.prompt) |
| 46 | .report(parms.report) | 47 | .report(parms.report) |
| 47 | .items(&parms.choices) | 48 | .items(&parms.choices); |
| 48 | .interact() | 49 | if let Some(default) = parms.default { |
| 49 | .context("failed to get choice") | 50 | if std::env::var("NGITTEST").is_err() { |
| 51 | choice.default(default); | ||
| 52 | } | ||
| 53 | } | ||
| 54 | choice.interact().context("failed to get choice") | ||
| 50 | } | 55 | } |
| 51 | } | 56 | } |
| 52 | 57 | ||
| @@ -110,6 +115,7 @@ impl PromptConfirmParms { | |||
| 110 | pub struct PromptChoiceParms { | 115 | pub struct PromptChoiceParms { |
| 111 | pub prompt: String, | 116 | pub prompt: String, |
| 112 | pub choices: Vec<String>, | 117 | pub choices: Vec<String>, |
| 118 | pub default: Option<usize>, | ||
| 113 | pub report: bool, | 119 | pub report: bool, |
| 114 | } | 120 | } |
| 115 | 121 | ||
| @@ -128,4 +134,9 @@ impl PromptChoiceParms { | |||
| 128 | self.choices = choices; | 134 | self.choices = choices; |
| 129 | self | 135 | self |
| 130 | } | 136 | } |
| 137 | |||
| 138 | pub fn with_default(mut self, index: usize) -> Self { | ||
| 139 | self.default = Some(index); | ||
| 140 | self | ||
| 141 | } | ||
| 131 | } | 142 | } |