use clap::Parser;
use eyre::eyre;
use std::io::{self, Write};
use tracing::info;
use crate::{Cli, OpenStackCliError};
use openstack_sdk::AsyncOpenStack;
#[derive(Parser)]
#[command(about = "Login to the cloud and get a valid authorization token")]
pub struct LoginCommand {
#[arg(long, action=clap::ArgAction::SetTrue)]
pub renew: bool,
}
impl LoginCommand {
pub async fn take_action(
&self,
_parsed_args: &Cli,
client: &mut AsyncOpenStack,
) -> Result<(), OpenStackCliError> {
info!("Show auth info");
if let Some(token) = client.get_auth_token() {
let mut stdout = io::stdout().lock();
stdout.write_all(&token.into_bytes())?;
return Ok(());
}
Err(eyre!("Authorization information missing").into())
}
}