pesde/src/cli/commands/auth/whoami.rs
2025-01-02 22:37:27 +01:00

26 lines
581 B
Rust

use crate::cli::auth::{get_token_login, get_tokens};
use clap::Args;
use colored::Colorize;
#[derive(Debug, Args)]
pub struct WhoAmICommand {}
impl WhoAmICommand {
pub async fn run(self, index_url: gix::Url, reqwest: reqwest::Client) -> anyhow::Result<()> {
let tokens = get_tokens().await?;
let token = match tokens.0.get(&index_url) {
Some(token) => token,
None => {
println!("not logged in into {index_url}");
return Ok(());
}
};
println!(
"logged in as {} into {index_url}",
get_token_login(&reqwest, token).await?.bold()
);
Ok(())
}
}