The latter is required to be able to pass on all configuration there is.
Showing the changes to git-credentials/src/program (2 of 4 files). Show all
Unified · Split
| @@ -7,7 +7,6 @@ impl Default for Cascade { · 6 unmodified lines | |||
| 7 | Cascade { | 7 | Cascade { |
| 8 | programs: Vec::new(), | 8 | programs: Vec::new(), |
| 9 | stderr: true, | 9 | stderr: true, |
| 10 | prompt: true, | ||
| 11 | } | 10 | } |
| 12 | } | 11 | } |
| 13 | } | 12 | } |
| @@ -31,23 +30,12 @@ impl Cascade { · 17 unmodified lines | |||
| 31 | .map(|name| vec![Program::from_custom_definition(name)]) | 30 | .map(|name| vec![Program::from_custom_definition(name)]) |
| 32 | .unwrap_or_default(); | 31 | .unwrap_or_default(); |
| 33 | 32 | ||
| 34 | Cascade { | 33 | Cascade { programs, stderr: true } |
| 35 | programs, | ||
| 36 | stderr: true, | ||
| 37 | prompt: true, | ||
| 38 | } | ||
| 39 | } | 34 | } |
| 40 | } | 35 | } |
| 41 | 36 | ||
| 42 | /// Builder | 37 | /// Builder |
| 43 | impl Cascade { | 38 | 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 | } | ||
| 51 | /// Extend the list of programs to run `programs`. | 39 | /// Extend the list of programs to run `programs`. |
| 52 | pub fn extend(mut self, programs: impl IntoIterator<Item = Program>) -> Self { | 40 | pub fn extend(mut self, programs: impl IntoIterator<Item = Program>) -> Self { |
| 53 | self.programs.extend(programs); | 41 | self.programs.extend(programs); |
| @@ -57,11 +45,12 @@ impl Cascade { · 3 unmodified lines | |||
| 57 | 45 | ||
| 58 | /// Finalize | 46 | /// Finalize |
| 59 | impl Cascade { | 47 | 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];=. | ||
| 61 | /// | 50 | /// |
| 62 | /// When _getting_ credentials, all programs are asked until the credentials are complete, stopping the cascade. | 51 | /// When _getting_ credentials, all programs are asked until the credentials are complete, stopping the cascade. |
| 63 | /// When _storing_ or _erasing_ all programs are instructed in order. | 52 | /// 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 { |
| 65 | action.context_mut().map(Context::destructure_url).transpose()?; | 54 | action.context_mut().map(Context::destructure_url).transpose()?; |
| 66 | 55 | ||
| 67 | for program in &mut self.programs { | 56 | for program in &mut self.programs { |
| @@ -103,18 +92,26 @@ impl Cascade { · 35 unmodified lines | |||
| 103 | } | 92 | } |
| 104 | } | 93 | } |
| 105 | 94 | ||
| 106 | if self.prompt { | 95 | if prompt.mode != git_prompt::Mode::Disable { |
| 107 | if let Some(ctx) = action.context_mut() { | 96 | if let Some(ctx) = action.context_mut() { |
| 108 | if ctx.username.is_none() { | 97 | if ctx.username.is_none() { |
| 109 | let prompt = ctx.to_prompt("Username"); | 98 | let message = ctx.to_prompt("Username"); |
| 110 | ctx.username = git_prompt::openly(&prompt) | 99 | prompt.mode = git_prompt::Mode::Visible; |
| 111 | .map_err(|err| protocol::Error::Prompt { prompt, source: err })? | 100 | ctx.username = git_prompt::ask(&message, &prompt) |
| 101 | .map_err(|err| protocol::Error::Prompt { | ||
| 102 | prompt: message, | ||
| 103 | source: err, | ||
| 104 | })? | ||
| 112 | .into(); | 105 | .into(); |
| 113 | } | 106 | } |
| 114 | if ctx.password.is_none() { | 107 | if ctx.password.is_none() { |
| 115 | let prompt = ctx.to_prompt("Password"); | 108 | let message = ctx.to_prompt("Password"); |
| 116 | ctx.password = git_prompt::securely(&prompt) | 109 | prompt.mode = git_prompt::Mode::Hidden; |
| 117 | .map_err(|err| protocol::Error::Prompt { prompt, source: err })? | 110 | ctx.password = git_prompt::ask(&message, &prompt) |
| 111 | .map_err(|err| protocol::Error::Prompt { | ||
| 112 | prompt: message, | ||
| 113 | source: err, | ||
| 114 | })? | ||
| 118 | .into(); | 115 | .into(); |
| 119 | } | 116 | } |
| 120 | } | 117 | } |
| @@ -10,8 +10,6 @@ pub struct Cascade { · 9 unmodified lines | |||
| 10 | pub programs: Vec<Program>, | 10 | pub programs: Vec<Program>, |
| 11 | /// If true, stderr is enabled when `programs` are run, which is the default. | 11 | /// If true, stderr is enabled when `programs` are run, which is the default. |
| 12 | pub stderr: bool, | 12 | pub stderr: bool, |
| 13 | /// If true, default true, we may prompt the user to fill in missing username or password. | ||
| 14 | prompt: bool, | ||
| 15 | } | 13 | } |
| 16 | 14 | ||
| 17 | mod cascade; | 15 | mod cascade; |