diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2023-09-01 00:00:00 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2023-09-13 09:24:49 +0000 |
| commit | 6423baebd92e45c9be85157c443dff42e65d8d14 (patch) | |
| tree | 6548edfd80d0cd9d1267378ebe816ec95e394137 /src/cli_interactor.rs | |
| parent | 5c5feaa732363e32e2a980a887fa42b4394b1a5e (diff) | |
refactor: rebuild app skeleton
Create skeleton for a complete rebuild of the prototype as a production
ready product.
Includes design patterns for:
- dependency injection
- unit testing with dependency mocking
- integration testing
- error handling
- config storage
BREAKING-CHANGE: ground-up redesign with incompatible protocol standards
Diffstat (limited to 'src/cli_interactor.rs')
| -rw-r--r-- | src/cli_interactor.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/cli_interactor.rs b/src/cli_interactor.rs new file mode 100644 index 0000000..2f28aee --- /dev/null +++ b/src/cli_interactor.rs | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | use anyhow::{bail, Result}; | ||
| 2 | use dialoguer::{theme::ColorfulTheme, Input}; | ||
| 3 | #[cfg(test)] | ||
| 4 | use mockall::*; | ||
| 5 | |||
| 6 | #[derive(Default)] | ||
| 7 | pub struct Interactor { | ||
| 8 | theme: ColorfulTheme, | ||
| 9 | } | ||
| 10 | |||
| 11 | #[cfg_attr(test, automock)] | ||
| 12 | pub trait InteractorPrompt { | ||
| 13 | fn input(&self, parms: PromptInputParms) -> Result<String>; | ||
| 14 | } | ||
| 15 | impl InteractorPrompt for Interactor { | ||
| 16 | fn input(&self, parms: PromptInputParms) -> Result<String> { | ||
| 17 | let input: String = Input::with_theme(&self.theme) | ||
| 18 | .with_prompt(parms.prompt) | ||
| 19 | .interact_text()?; | ||
| 20 | Ok(input) | ||
| 21 | } | ||
| 22 | } | ||
| 23 | |||
| 24 | #[derive(Default)] | ||
| 25 | pub struct PromptInputParms { | ||
| 26 | pub prompt: String, | ||
| 27 | } | ||
| 28 | |||
| 29 | impl PromptInputParms { | ||
| 30 | pub fn with_prompt<S: Into<String>>(mut self, prompt: S) -> Self { | ||
| 31 | self.prompt = prompt.into(); | ||
| 32 | self | ||
| 33 | } | ||
| 34 | } | ||