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 | 7 | Cascade { |
| 8 | 8 | programs: Vec::new(), |
| 9 | 9 | stderr: true, |
| 10 | − prompt: true, | |
| 11 | 10 | } |
| 12 | 11 | } |
| 13 | 12 | } |
| @@ -31,23 +30,12 @@ impl Cascade { · 17 unmodified lines | ||
| 31 | 30 | .map(|name| vec![Program::from_custom_definition(name)]) |
| 32 | 31 | .unwrap_or_default(); |
| 33 | 32 | |
| 34 | − Cascade { | |
| 35 | − programs, | |
| 36 | − stderr: true, | |
| 37 | − prompt: true, | |
| 38 | − } | |
| 33 | + Cascade { programs, stderr: true } | |
| 39 | 34 | } |
| 40 | 35 | } |
| 41 | 36 | |
| 42 | 37 | /// Builder |
| 43 | 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 | 39 | /// Extend the list of programs to run `programs`. |
| 52 | 40 | pub fn extend(mut self, programs: impl IntoIterator<Item = Program>) -> Self { |
| 53 | 41 | self.programs.extend(programs); |
| @@ -57,11 +45,12 @@ impl Cascade { · 3 unmodified lines | ||
| 57 | 45 | |
| 58 | 46 | /// Finalize |
| 59 | 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 | 51 | /// When _getting_ credentials, all programs are asked until the credentials are complete, stopping the cascade. |
| 63 | 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 | 54 | action.context_mut().map(Context::destructure_url).transpose()?; |
| 66 | 55 | |
| 67 | 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 | 96 | if let Some(ctx) = action.context_mut() { |
| 108 | 97 | 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 | + })? | |
| 112 | 105 | .into(); |
| 113 | 106 | } |
| 114 | 107 | 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 | + })? | |
| 118 | 115 | .into(); |
| 119 | 116 | } |
| 120 | 117 | } |
| @@ -10,8 +10,6 @@ pub struct Cascade { · 9 unmodified lines | ||
| 10 | 10 | pub programs: Vec<Program>, |
| 11 | 11 | /// If true, stderr is enabled when `programs` are run, which is the default. |
| 12 | 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 | 15 | mod cascade; |