theater_cli/commands/
inspect.rs1use anyhow::Result;
2use clap::Parser;
3use std::net::SocketAddr;
4use tracing::debug;
5
6use theater::id::TheaterId;
7
8use crate::{error::CliError, output::formatters::ActorInspection, CommandContext};
9
10#[derive(Debug, Parser)]
11pub struct InspectArgs {
12 #[arg(required = true)]
14 pub actor_id: TheaterId,
15
16 #[arg(short, long)]
18 pub address: Option<SocketAddr>,
19
20 #[arg(short, long)]
22 pub detailed: bool,
23}
24
25pub async fn execute_async(args: &InspectArgs, ctx: &CommandContext) -> Result<(), CliError> {
27 debug!("Inspecting actor: {}", args.actor_id);
28
29 let address = ctx.server_address(args.address);
31 debug!("Connecting to server at: {}", address);
32
33 let client = ctx.create_client();
35 client
36 .connect()
37 .await
38 .map_err(|e| CliError::connection_failed(address, e))?;
39
40 debug!("Getting actor status");
42 let status = client
43 .get_actor_status(&args.actor_id.to_string())
44 .await
45 .map_err(|_e| CliError::actor_not_found(&args.actor_id.to_string()))?;
46
47 debug!("Getting actor state");
48 let state_result = client.get_actor_state(&args.actor_id.to_string()).await;
49 let state = match state_result {
50 Ok(ref state_value) => {
51 if state_value.is_null() {
52 None
53 } else {
54 Some(state_value)
55 }
56 }
57 _ => None,
58 };
59
60 debug!("Getting actor events");
61 let events_result = client.get_actor_events(&args.actor_id.to_string()).await;
62 let events = match events_result {
63 Ok(events) => events,
64 Err(_) => vec![],
65 };
66
67 let metrics: Option<serde_json::Value> = None;
69
70 let inspection = ActorInspection {
72 id: args.actor_id.clone(),
73 status: format!("{:?}", status),
74 state: state.cloned(),
75 events: events.clone(),
76 metrics,
77 detailed: args.detailed,
78 };
79
80 ctx.output.output(&inspection, None)?;
81 Ok(())
82}