use std::fmt::{Debug, Display};
#[derive(Debug, Clone)]
pub enum Password {
Owner(Secret<String>),
User(Secret<String>),
}
impl Password {
pub fn owner(value: impl Into<String>) -> Self {
Self::Owner(Secret(value.into()))
}
pub fn user(value: impl Into<String>) -> Self {
Self::User(Secret(value.into()))
}
pub fn push_arg(&self, args: &mut Vec<String>) {
match self {
Password::Owner(Secret(password)) => {
if !password.is_empty() {
args.push("-opw".to_string());
args.push(password.to_string())
}
}
Password::User(Secret(password)) => {
if !password.is_empty() {
args.push("-upw".to_string());
args.push(password.to_string())
}
}
}
}
}
#[derive(Clone)]
pub struct Secret<T>(pub T);
impl<T> From<T> for Secret<T> {
fn from(value: T) -> Self {
Self(value)
}
}
impl<T> Debug for Secret<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("******")
}
}
impl<T> Display for Secret<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("******")
}
}