Skip to main content

palladium_cli/commands/
events.rs

1use crate::client::ControlPlaneClient;
2use crate::client::Endpoint;
3use crate::CliResult;
4use clap::Args;
5use schemars::JsonSchema;
6use serde::Serialize;
7use serde_json::json;
8
9#[derive(Args, Debug, Serialize, JsonSchema)]
10#[serde(rename_all = "kebab-case")]
11pub struct EventsArgs {
12    /// Output in JSON format.
13    #[arg(long, default_value_t = true)]
14    pub json: bool,
15    /// Keep streaming events.
16    #[arg(long, default_value_t = true)]
17    pub follow: bool,
18}
19
20pub fn run(args: &EventsArgs, endpoint: &Endpoint) -> CliResult {
21    let mut client = ControlPlaneClient::connect_endpoint(endpoint)?;
22
23    // In a real implementation, this would be a long-lived connection
24    // that streams from the control plane's event bus.
25    // For now, we'll implement a mock or a single-call version.
26
27    if args.follow {
28        println!("Streaming events (press Ctrl-C to stop)...");
29        // Mock event stream
30        loop {
31            let event = json!({
32                "timestamp": std::time::SystemTime::now()
33                    .duration_since(std::time::UNIX_EPOCH)
34                    .unwrap_or_default()
35                    .as_secs(),
36                "type": "heartbeat",
37                "data": { "status": "active" }
38            });
39            println!("{}", serde_json::to_string(&event)?);
40            std::thread::sleep(std::time::Duration::from_secs(5));
41        }
42    } else {
43        let events = client.call("engine.events", json!({"follow": false}))?;
44        println!("{}", serde_json::to_string_pretty(&events)?);
45    }
46
47    Ok(())
48}