From 6423baebd92e45c9be85157c443dff42e65d8d14 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Fri, 1 Sep 2023 00:00:00 +0000 Subject: 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 --- src/cli_interactor.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/cli_interactor.rs (limited to 'src/cli_interactor.rs') 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 @@ +use anyhow::{bail, Result}; +use dialoguer::{theme::ColorfulTheme, Input}; +#[cfg(test)] +use mockall::*; + +#[derive(Default)] +pub struct Interactor { + theme: ColorfulTheme, +} + +#[cfg_attr(test, automock)] +pub trait InteractorPrompt { + fn input(&self, parms: PromptInputParms) -> Result; +} +impl InteractorPrompt for Interactor { + fn input(&self, parms: PromptInputParms) -> Result { + let input: String = Input::with_theme(&self.theme) + .with_prompt(parms.prompt) + .interact_text()?; + Ok(input) + } +} + +#[derive(Default)] +pub struct PromptInputParms { + pub prompt: String, +} + +impl PromptInputParms { + pub fn with_prompt>(mut self, prompt: S) -> Self { + self.prompt = prompt.into(); + self + } +} -- cgit v1.2.3