upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/cli_interactor.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/cli_interactor.rs')
-rw-r--r--src/cli_interactor.rs27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/cli_interactor.rs b/src/cli_interactor.rs
index d7de087..cf6e3d0 100644
--- a/src/cli_interactor.rs
+++ b/src/cli_interactor.rs
@@ -1,5 +1,5 @@
1use anyhow::Result; 1use anyhow::Result;
2use dialoguer::{theme::ColorfulTheme, Input, Password}; 2use dialoguer::{theme::ColorfulTheme, Confirm, Input, Password};
3#[cfg(test)] 3#[cfg(test)]
4use mockall::*; 4use mockall::*;
5 5
@@ -12,6 +12,7 @@ pub struct Interactor {
12pub trait InteractorPrompt { 12pub trait InteractorPrompt {
13 fn input(&self, parms: PromptInputParms) -> Result<String>; 13 fn input(&self, parms: PromptInputParms) -> Result<String>;
14 fn password(&self, parms: PromptPasswordParms) -> Result<String>; 14 fn password(&self, parms: PromptPasswordParms) -> Result<String>;
15 fn confirm(&self, params: PromptConfirmParms) -> Result<bool>;
15} 16}
16impl InteractorPrompt for Interactor { 17impl InteractorPrompt for Interactor {
17 fn input(&self, parms: PromptInputParms) -> Result<String> { 18 fn input(&self, parms: PromptInputParms) -> Result<String> {
@@ -29,6 +30,13 @@ impl InteractorPrompt for Interactor {
29 let pass: String = p.interact()?; 30 let pass: String = p.interact()?;
30 Ok(pass) 31 Ok(pass)
31 } 32 }
33 fn confirm(&self, params: PromptConfirmParms) -> Result<bool> {
34 let confirm: bool = Confirm::with_theme(&self.theme)
35 .with_prompt(params.prompt)
36 .default(params.default)
37 .interact()?;
38 Ok(confirm)
39 }
32} 40}
33 41
34#[derive(Default)] 42#[derive(Default)]
@@ -59,3 +67,20 @@ impl PromptPasswordParms {
59 self 67 self
60 } 68 }
61} 69}
70
71#[derive(Default)]
72pub struct PromptConfirmParms {
73 pub prompt: String,
74 pub default: bool,
75}
76
77impl PromptConfirmParms {
78 pub fn with_prompt<S: Into<String>>(mut self, prompt: S) -> Self {
79 self.prompt = prompt.into();
80 self
81 }
82 pub fn with_default(mut self, default: bool) -> Self {
83 self.default = default;
84 self
85 }
86}