upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/lib/cli_interactor.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-11-21 16:53:17 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2024-11-21 16:53:17 +0000
commitf79014235e85554e3661b3f2a02b8fa88bc192ff (patch)
treefceec3ff2df212148a3420af7cef81a3f818463e /src/lib/cli_interactor.rs
parent91b0eac4daf92b7b740267ef203a1a8ba591974b (diff)
feat(login): overhaul login experience
* simplify login menu, making it more accessable to newcomers and easier to select remote signer options * enable `ngit login` to work from anywhere (not just a git repo) * assume fresh login details saved to global git config but fallback to local repository * maintain local repository login via `ngit login --local` * maintain login via CLI arguments eg `ngit send --nsec nsec123` * nudge users to remember nsec when pasting in ncryptsec for a better UX, whilst maintaining the option to be prompted for password everytime * create placeholder menu items for help menu and create account
Diffstat (limited to 'src/lib/cli_interactor.rs')
-rw-r--r--src/lib/cli_interactor.rs30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/lib/cli_interactor.rs b/src/lib/cli_interactor.rs
index dcaccf1..7d67961 100644
--- a/src/lib/cli_interactor.rs
+++ b/src/lib/cli_interactor.rs
@@ -24,11 +24,13 @@ impl InteractorPrompt for Interactor {
24 if !parms.default.is_empty() { 24 if !parms.default.is_empty() {
25 input.default(parms.default); 25 input.default(parms.default);
26 } 26 }
27 input.report(parms.report);
27 Ok(input.interact_text()?) 28 Ok(input.interact_text()?)
28 } 29 }
29 fn password(&self, parms: PromptPasswordParms) -> Result<String> { 30 fn password(&self, parms: PromptPasswordParms) -> Result<String> {
30 let mut p = Password::with_theme(&self.theme); 31 let mut p = Password::with_theme(&self.theme);
31 p.with_prompt(parms.prompt); 32 p.with_prompt(parms.prompt);
33 p.report(parms.report);
32 if parms.confirm { 34 if parms.confirm {
33 p.with_confirmation("confirm password", "passwords didnt match..."); 35 p.with_confirmation("confirm password", "passwords didnt match...");
34 } 36 }
@@ -44,10 +46,10 @@ impl InteractorPrompt for Interactor {
44 } 46 }
45 fn choice(&self, parms: PromptChoiceParms) -> Result<usize> { 47 fn choice(&self, parms: PromptChoiceParms) -> Result<usize> {
46 let mut choice = dialoguer::Select::with_theme(&self.theme); 48 let mut choice = dialoguer::Select::with_theme(&self.theme);
47 choice 49 if !parms.prompt.is_empty() {
48 .with_prompt(parms.prompt) 50 choice.with_prompt(parms.prompt);
49 .report(parms.report) 51 }
50 .items(&parms.choices); 52 choice.report(parms.report).items(&parms.choices);
51 if let Some(default) = parms.default { 53 if let Some(default) = parms.default {
52 if std::env::var("NGITTEST").is_err() { 54 if std::env::var("NGITTEST").is_err() {
53 choice.default(default); 55 choice.default(default);
@@ -73,6 +75,7 @@ impl InteractorPrompt for Interactor {
73pub struct PromptInputParms { 75pub struct PromptInputParms {
74 pub prompt: String, 76 pub prompt: String,
75 pub default: String, 77 pub default: String,
78 pub report: bool,
76 pub optional: bool, 79 pub optional: bool,
77} 80}
78 81
@@ -89,12 +92,18 @@ impl PromptInputParms {
89 self.optional = true; 92 self.optional = true;
90 self 93 self
91 } 94 }
95
96 pub fn dont_report(mut self) -> Self {
97 self.report = false;
98 self
99 }
92} 100}
93 101
94#[derive(Default)] 102#[derive(Default)]
95pub struct PromptPasswordParms { 103pub struct PromptPasswordParms {
96 pub prompt: String, 104 pub prompt: String,
97 pub confirm: bool, 105 pub confirm: bool,
106 pub report: bool,
98} 107}
99 108
100impl PromptPasswordParms { 109impl PromptPasswordParms {
@@ -106,6 +115,10 @@ impl PromptPasswordParms {
106 self.confirm = true; 115 self.confirm = true;
107 self 116 self
108 } 117 }
118 pub fn dont_report(mut self) -> Self {
119 self.report = false;
120 self
121 }
109} 122}
110 123
111#[derive(Default)] 124#[derive(Default)]
@@ -140,10 +153,11 @@ impl PromptChoiceParms {
140 self 153 self
141 } 154 }
142 155
143 // pub fn dont_report(mut self) -> Self { 156 pub fn dont_report(mut self) -> Self {
144 // self.report = false; 157 self.report = false;
145 // self 158 self
146 // } 159 }
160
147 pub fn with_choices(mut self, choices: Vec<String>) -> Self { 161 pub fn with_choices(mut self, choices: Vec<String>) -> Self {
148 self.choices = choices; 162 self.choices = choices;
149 self 163 self