diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-02-15 10:16:00 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-02-15 10:16:00 +0000 |
| commit | b7c24559aa2758820039295ac0f6120dfdec550e (patch) | |
| tree | 9d5fa8e1ea96bea6757232a9beea3e9add493ed3 /src/cli_interactor.rs | |
| parent | 6a4519b79cd36d1edbb492a3c98e2a3a0b42e0e9 (diff) | |
fix: allow optional description and web
also add a default web
Diffstat (limited to 'src/cli_interactor.rs')
| -rw-r--r-- | src/cli_interactor.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/cli_interactor.rs b/src/cli_interactor.rs index c6cd4e5..693e9fd 100644 --- a/src/cli_interactor.rs +++ b/src/cli_interactor.rs | |||
| @@ -19,6 +19,8 @@ impl InteractorPrompt for Interactor { | |||
| 19 | fn input(&self, parms: PromptInputParms) -> Result<String> { | 19 | fn input(&self, parms: PromptInputParms) -> Result<String> { |
| 20 | let input: String = Input::with_theme(&self.theme) | 20 | let input: String = Input::with_theme(&self.theme) |
| 21 | .with_prompt(parms.prompt) | 21 | .with_prompt(parms.prompt) |
| 22 | .default(parms.default) | ||
| 23 | .allow_empty(parms.optional) | ||
| 22 | .interact_text()?; | 24 | .interact_text()?; |
| 23 | Ok(input) | 25 | Ok(input) |
| 24 | } | 26 | } |
| @@ -51,6 +53,8 @@ impl InteractorPrompt for Interactor { | |||
| 51 | #[derive(Default)] | 53 | #[derive(Default)] |
| 52 | pub struct PromptInputParms { | 54 | pub struct PromptInputParms { |
| 53 | pub prompt: String, | 55 | pub prompt: String, |
| 56 | pub default: String, | ||
| 57 | pub optional: bool, | ||
| 54 | } | 58 | } |
| 55 | 59 | ||
| 56 | impl PromptInputParms { | 60 | impl PromptInputParms { |
| @@ -58,6 +62,14 @@ impl PromptInputParms { | |||
| 58 | self.prompt = prompt.into(); | 62 | self.prompt = prompt.into(); |
| 59 | self | 63 | self |
| 60 | } | 64 | } |
| 65 | pub fn with_default<S: Into<String>>(mut self, default: S) -> Self { | ||
| 66 | self.default = default.into(); | ||
| 67 | self | ||
| 68 | } | ||
| 69 | pub fn optional(mut self) -> Self { | ||
| 70 | self.optional = true; | ||
| 71 | self | ||
| 72 | } | ||
| 61 | } | 73 | } |
| 62 | 74 | ||
| 63 | #[derive(Default)] | 75 | #[derive(Default)] |