iggy_cli/commands/binary_system/
me.rs1use crate::commands::cli_command::{CliCommand, PRINT_TARGET};
20use anyhow::Context;
21use async_trait::async_trait;
22use comfy_table::Table;
23use iggy_common::Client;
24use tracing::{Level, event};
25
26#[derive(Default)]
27pub struct GetMeCmd;
28
29impl GetMeCmd {
30 pub fn new() -> Self {
31 Self
32 }
33}
34
35#[async_trait]
36impl CliCommand for GetMeCmd {
37 fn explain(&self) -> String {
38 "me command".to_owned()
39 }
40
41 async fn execute_cmd(&mut self, client: &dyn Client) -> anyhow::Result<(), anyhow::Error> {
42 let client_info = client
43 .get_me()
44 .await
45 .with_context(|| "Problem sending get_me command".to_owned())?;
46
47 let mut table = Table::new();
48
49 table.set_header(vec!["Property", "Value"]);
50 table.add_row(vec![
51 "Client ID",
52 format!("{}", client_info.client_id).as_str(),
53 ]);
54 if let Some(user_id) = client_info.user_id {
55 table.add_row(vec!["User ID", format!("{user_id}").as_str()]);
56 }
57 table.add_row(vec!["Address", client_info.address.as_str()]);
58 table.add_row(vec!["Transport", client_info.transport.as_str()]);
59
60 event!(target: PRINT_TARGET, Level::INFO, "{table}");
61
62 Ok(())
63 }
64}