use std::path::Path;
pub trait Prompter: Send {
fn prompt_username_password(&mut self, url: &str, git_config: &git2::Config) -> Option<(String, String)>;
fn prompt_password(&mut self, username: &str, url: &str, git_config: &git2::Config) -> Option<String>;
fn prompt_ssh_key_passphrase(&mut self, private_key_path: &Path, git_config: &git2::Config) -> Option<String>;
}
pub(crate) fn wrap_prompter<P>(prompter: P) -> Box<dyn ClonePrompter>
where
P: Prompter + Clone + 'static,
{
Box::new(prompter)
}
pub(crate) trait ClonePrompter: Prompter {
fn dyn_clone(&self) -> Box<dyn ClonePrompter>;
fn as_prompter_mut(&mut self) -> &mut dyn Prompter;
}
impl<P> ClonePrompter for P
where
P: Prompter + Clone + 'static,
{
fn dyn_clone(&self) -> Box<dyn ClonePrompter> {
Box::new(self.clone())
}
fn as_prompter_mut(&mut self) -> &mut dyn Prompter {
self
}
}
impl Clone for Box<dyn ClonePrompter> {
fn clone(&self) -> Self {
self.dyn_clone()
}
}