awsmfa 0.2.1

This tool automates Multi-Factor Authentication (MFA) process in using awscli.
Documentation
use crate::{get_otp, Config, Result};

use anyhow::anyhow;
use cli_clipboard::{ClipboardContext, ClipboardProvider};

#[derive(clap::Args)]
pub struct Args {
    /// Profile name
    #[arg(short, long)]
    profile: Option<String>,

    /// Whether put the one time password to clipboard or not
    #[arg(short, long)]
    clip: bool,
}

pub fn run(config: Config, args: &Args) -> Result<()> {
    let Args { profile, clip } = args;
    let profile = profile.as_deref().unwrap_or("default");
    let password = get_otp(&config, profile)?;

    println!("{password}");

    if *clip {
        let mut ctx = ClipboardContext::new().map_err(|e| anyhow!("{}", e))?;
        ctx.set_contents(password).map_err(|e| anyhow!("{}", e))?;
    }

    Ok(())
}