pesde/src/cli/commands/auth/whoami.rs
daimond113 95896091cd
refactor: switch out dependencies
Switches the `colored` crate to the `console`
crate. Additionally, to optimize the compiled
program's size switches the `inquire` crate's
backend from `crossterm` to `console`. Console was
picked out because we depend on `indicatif` which
only supports `console`.

Also switches from `winreg` to `windows-registry`,
which `reqwest` depends on to optimize size even
further. Currently has to duplicate dependencies,
as `reqwest` depends on an older version but will
become optimized once `reqwest` updates to the
latest version of the crate.

Signed-off-by: daimond113 <contact@daimond113.com>
2025-01-19 22:29:27 +01:00

26 lines
585 B
Rust

use crate::cli::auth::{get_token_login, get_tokens};
use clap::Args;
use console::style;
#[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}",
style(get_token_login(&reqwest, token).await?).bold()
);
Ok(())
}
}