1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use clap::Parser;
use colored::Colorize;

use crate::config::WasmerEnv;

use super::AsyncCliCommand;

#[derive(Debug, Parser)]
/// The options for the `wasmer whoami` subcommand
pub struct Whoami {
    #[clap(flatten)]
    env: WasmerEnv,
}

#[async_trait::async_trait]
impl AsyncCliCommand for Whoami {
    type Output = ();

    /// Execute `wasmer whoami`
    async fn run_async(self) -> Result<Self::Output, anyhow::Error> {
        let client = self.env.client_unauthennticated()?;
        let host_str = self.env.registry_public_url()?.host_str().unwrap().bold();
        let user = wasmer_backend_api::query::current_user(&client)
            .await?
            .ok_or_else(|| anyhow::anyhow!("Not logged in registry {host_str}"))?;
        println!(
            "Logged into registry {host_str} as user {}",
            user.username.bold()
        );
        Ok(())
    }
}