use super::theme::ColoredTheme;
use dialoguer::PasswordInput;
use std::io::Result;
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
pub struct Secret {
#[structopt(short, long)]
message: String,
#[structopt(short, long, requires = "error")]
confirm: Option<String>,
#[structopt(short, long, requires = "confirm")]
error: Option<String>,
#[structopt(short, long)]
allow_empty: bool,
}
impl Secret {
pub fn run(&self) -> Result<()> {
let theme = ColoredTheme::default();
let mut input = PasswordInput::with_theme(&theme);
input
.with_prompt(&self.message)
.allow_empty_password(self.allow_empty);
if self.confirm.is_some() {
input.with_confirmation(
self.confirm.as_ref().unwrap(),
&self.error.as_ref().unwrap(),
);
}
let value = input.interact()?;
println!("{}", value);
Ok(())
}
}