upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/cli_interactor.rs27
1 files changed, 13 insertions, 14 deletions
diff --git a/src/lib/cli_interactor.rs b/src/lib/cli_interactor.rs
index 1b74101..8fca81d 100644
--- a/src/lib/cli_interactor.rs
+++ b/src/lib/cli_interactor.rs
@@ -19,20 +19,21 @@ pub trait InteractorPrompt {
19} 19}
20impl InteractorPrompt for Interactor { 20impl InteractorPrompt for Interactor {
21 fn input(&self, parms: PromptInputParms) -> Result<String> { 21 fn input(&self, parms: PromptInputParms) -> Result<String> {
22 let mut input = Input::with_theme(&self.theme); 22 let mut input = Input::with_theme(&self.theme)
23 input.with_prompt(parms.prompt).allow_empty(parms.optional); 23 .with_prompt(parms.prompt)
24 .allow_empty(parms.optional)
25 .report(parms.report);
24 if !parms.default.is_empty() { 26 if !parms.default.is_empty() {
25 input.default(parms.default); 27 input = input.default(parms.default);
26 } 28 }
27 input.report(parms.report);
28 Ok(input.interact_text()?) 29 Ok(input.interact_text()?)
29 } 30 }
30 fn password(&self, parms: PromptPasswordParms) -> Result<String> { 31 fn password(&self, parms: PromptPasswordParms) -> Result<String> {
31 let mut p = Password::with_theme(&self.theme); 32 let mut p = Password::with_theme(&self.theme)
32 p.with_prompt(parms.prompt); 33 .with_prompt(parms.prompt)
33 p.report(parms.report); 34 .report(parms.report);
34 if parms.confirm { 35 if parms.confirm {
35 p.with_confirmation("confirm password", "passwords didnt match..."); 36 p = p.with_confirmation("confirm password", "passwords didnt match...");
36 } 37 }
37 let pass: String = p.interact()?; 38 let pass: String = p.interact()?;
38 Ok(pass) 39 Ok(pass)
@@ -45,27 +46,25 @@ impl InteractorPrompt for Interactor {
45 Ok(confirm) 46 Ok(confirm)
46 } 47 }
47 fn choice(&self, parms: PromptChoiceParms) -> Result<usize> { 48 fn choice(&self, parms: PromptChoiceParms) -> Result<usize> {
48 let mut choice = dialoguer::Select::with_theme(&self.theme); 49 let mut choice = dialoguer::Select::with_theme(&self.theme)
49 choice
50 .with_prompt(parms.prompt) 50 .with_prompt(parms.prompt)
51 .report(parms.report) 51 .report(parms.report)
52 .items(&parms.choices); 52 .items(&parms.choices);
53 if let Some(default) = parms.default { 53 if let Some(default) = parms.default {
54 if std::env::var("NGITTEST").is_err() { 54 if std::env::var("NGITTEST").is_err() {
55 choice.default(default); 55 choice = choice.default(default);
56 } 56 }
57 } 57 }
58 choice.interact().context("failed to get choice") 58 choice.interact().context("failed to get choice")
59 } 59 }
60 fn multi_choice(&self, parms: PromptMultiChoiceParms) -> Result<Vec<usize>> { 60 fn multi_choice(&self, parms: PromptMultiChoiceParms) -> Result<Vec<usize>> {
61 // the colorful theme is not very clear so falling back to default 61 // the colorful theme is not very clear so falling back to default
62 let mut choice = dialoguer::MultiSelect::default(); 62 let mut choice = dialoguer::MultiSelect::default()
63 choice
64 .with_prompt(parms.prompt) 63 .with_prompt(parms.prompt)
65 .report(parms.report) 64 .report(parms.report)
66 .items(&parms.choices); 65 .items(&parms.choices);
67 if let Some(defaults) = parms.defaults { 66 if let Some(defaults) = parms.defaults {
68 choice.defaults(&defaults); 67 choice = choice.defaults(&defaults);
69 } 68 }
70 choice.interact().context("failed to get choice") 69 choice.interact().context("failed to get choice")
71 } 70 }