use anyhow::Result;
use pimalaya_cli::wizard::keyring::{self, SecretChoice};
use pimalaya_config::secret::Secret;
use crate::wizard::account::{command_secret, shell_secret};
pub fn configure_password(label: &str, key_default: &str) -> Result<Secret> {
to_secret(keyring::prompt_secret(label, key_default)?)
}
pub fn configure_token(label: &str, key_default: &str, oauth: bool) -> Result<Secret> {
to_secret(keyring::prompt_token(label, key_default, oauth)?)
}
fn to_secret(choice: SecretChoice) -> Result<Secret> {
Ok(match choice {
SecretChoice::Command(argv) => command_secret(argv)?,
SecretChoice::Shell(line) => shell_secret(&line)?,
SecretChoice::Raw(secret) => Secret::Raw(secret),
})
}