History

credential-cascade now passes on prompt options (#450)

The latter is required to be able to pass on all configuration there is.

Sebastian Thiel committed 4 years ago

Commit baad8a01 parent 51930a24 files · +33 −32Browse files

Showing the changes to git-credentials/src/program (2 of 4 files). Show all

Unified · Split

2 files
  1. git-credentials/src/program/cascade.rs +19 −22
  2. git-credentials/src/program/mod.rs +0 −2
git-credentials/src/program/cascade.rs+19−22
@@ -7,7 +7,6 @@ impl Default for Cascade { · 6 unmodified lines
77 Cascade {
88 programs: Vec::new(),
99 stderr: true,
10− prompt: true,
1110 }
1211 }
1312 }
@@ -31,23 +30,12 @@ impl Cascade { · 17 unmodified lines
3130 .map(|name| vec![Program::from_custom_definition(name)])
3231 .unwrap_or_default();
3332
34− Cascade {
35− programs,
36− stderr: true,
37− prompt: true,
38− }
33+ Cascade { programs, stderr: true }
3934 }
4035 }
4136
4237 /// Builder
4338 impl Cascade {
44− /// Disable prompting to assure we only interact with stored or already present credentials.
45− ///
46− /// Note that this is only meaningful with the `prompt` feature enabled.
47− pub fn disable_prompt(mut self) -> Self {
48− self.prompt = false;
49− self
50− }
5139 /// Extend the list of programs to run `programs`.
5240 pub fn extend(mut self, programs: impl IntoIterator<Item = Program>) -> Self {
5341 self.programs.extend(programs);
@@ -57,11 +45,12 @@ impl Cascade { · 3 unmodified lines
5745
5846 /// Finalize
5947 impl Cascade {
60− /// Invoke the cascade by `invoking` each program with `action`.
48+ /// Invoke the cascade by `invoking` each program with `action`, and configuring potential prompts with `prompt` options.
49+ /// The latter can also be used to disable the prompt entirely when setting the `mode` to [`Disable`][git_prompt::Mode::Disable];=.
6150 ///
6251 /// When _getting_ credentials, all programs are asked until the credentials are complete, stopping the cascade.
6352 /// When _storing_ or _erasing_ all programs are instructed in order.
64− pub fn invoke(&mut self, mut action: helper::Action) -> protocol::Result {
53+ pub fn invoke(&mut self, mut action: helper::Action, mut prompt: git_prompt::Options<'_>) -> protocol::Result {
6554 action.context_mut().map(Context::destructure_url).transpose()?;
6655
6756 for program in &mut self.programs {
@@ -103,18 +92,26 @@ impl Cascade { · 35 unmodified lines
10392 }
10493 }
10594
106− if self.prompt {
95+ if prompt.mode != git_prompt::Mode::Disable {
10796 if let Some(ctx) = action.context_mut() {
10897 if ctx.username.is_none() {
109− let prompt = ctx.to_prompt("Username");
110− ctx.username = git_prompt::openly(&prompt)
111− .map_err(|err| protocol::Error::Prompt { prompt, source: err })?
98+ let message = ctx.to_prompt("Username");
99+ prompt.mode = git_prompt::Mode::Visible;
100+ ctx.username = git_prompt::ask(&message, &prompt)
101+ .map_err(|err| protocol::Error::Prompt {
102+ prompt: message,
103+ source: err,
104+ })?
112105 .into();
113106 }
114107 if ctx.password.is_none() {
115− let prompt = ctx.to_prompt("Password");
116− ctx.password = git_prompt::securely(&prompt)
117− .map_err(|err| protocol::Error::Prompt { prompt, source: err })?
108+ let message = ctx.to_prompt("Password");
109+ prompt.mode = git_prompt::Mode::Hidden;
110+ ctx.password = git_prompt::ask(&message, &prompt)
111+ .map_err(|err| protocol::Error::Prompt {
112+ prompt: message,
113+ source: err,
114+ })?
118115 .into();
119116 }
120117 }
git-credentials/src/program/mod.rs+0−2
@@ -10,8 +10,6 @@ pub struct Cascade { · 9 unmodified lines
1010 pub programs: Vec<Program>,
1111 /// If true, stderr is enabled when `programs` are run, which is the default.
1212 pub stderr: bool,
13− /// If true, default true, we may prompt the user to fill in missing username or password.
14− prompt: bool,
1513 }
1614
1715 mod cascade;