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:
authorDanConwayDev <DanConwayDev@protonmail.com>2023-09-01 00:00:00 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2023-09-13 09:24:49 +0000
commit6423baebd92e45c9be85157c443dff42e65d8d14 (patch)
tree6548edfd80d0cd9d1267378ebe816ec95e394137 /src/cli_interactor.rs
parent5c5feaa732363e32e2a980a887fa42b4394b1a5e (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.rs34
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 @@
1use anyhow::{bail, Result};
2use dialoguer::{theme::ColorfulTheme, Input};
3#[cfg(test)]
4use mockall::*;
5
6#[derive(Default)]
7pub struct Interactor {
8 theme: ColorfulTheme,
9}
10
11#[cfg_attr(test, automock)]
12pub trait InteractorPrompt {
13 fn input(&self, parms: PromptInputParms) -> Result<String>;
14}
15impl 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)]
25pub struct PromptInputParms {
26 pub prompt: String,
27}
28
29impl PromptInputParms {
30 pub fn with_prompt<S: Into<String>>(mut self, prompt: S) -> Self {
31 self.prompt = prompt.into();
32 self
33 }
34}