Files
arje/crates/ente-bus/examples/busctl.rs
T
Sergio d6b8f18b43 Pausa: 11 crates del fractal Ente #0 con cerebro completo
PID 1 boot + bus interno autenticado + cerebro KCL/Rust:
- 6 lib crates de infra (card, bus, cas, kernel, soma, wasm, snapshot)
- ente-brain: motor de reglas O(1), observer Shannon, cristalización,
  audit hash-chain, persistencia rules.k, Prometheus /metrics
- KCL schemas card.k + rule.k como gramática autoritativa
- compat-logind D-Bus, ente-echo demo provider, ente-zero PID 1
- 22 tests OK, ~3.8k LOC Rust + ~300 LOC KCL

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-03 22:57:44 +00:00

53 lines
1.9 KiB
Rust

//! busctl: cliente CLI para el bus interno del fractal.
//!
//! Uso:
//! cargo run --example busctl -- list-entes
//! cargo run --example busctl -- announce
//! cargo run --example busctl -- power-off
//!
//! Si `ENTE_BUS_SOCK` no está en el entorno, cae al path dev por defecto.
use ente_bus::{BusClient, BusRequest};
use std::env;
#[tokio::main(flavor = "current_thread")]
async fn main() -> anyhow::Result<()> {
let args: Vec<String> = env::args().collect();
let cmd = args.get(1).map(|s| s.as_str()).unwrap_or("list-entes");
let mut client = match BusClient::from_env().await {
Ok(c) => c,
Err(_) => {
let user = env::var("USER").unwrap_or_else(|_| "ente".into());
let runtime = env::var("XDG_RUNTIME_DIR")
.unwrap_or_else(|_| env::var("TMPDIR").unwrap_or_else(|_| "/tmp".into()));
let path = format!("{runtime}/ente-bus-{user}.sock");
eprintln!("ENTE_BUS_SOCK no definido, intentando {path}");
BusClient::connect(&path).await?
}
};
let req = match cmd {
"list-entes" => BusRequest::ListEntes,
"announce" => BusRequest::Announce { capabilities: vec![] },
"power-off" => BusRequest::PowerOff { interactive: false },
"reboot" => BusRequest::Reboot { interactive: false },
"suspend" => BusRequest::Suspend { interactive: false },
"invoke-echo" => {
let msg = args.get(2).map(|s| s.as_str()).unwrap_or("hola");
BusRequest::Invoke {
cap: ente_echo::echo_capability(),
blob: msg.as_bytes().to_vec(),
}
}
other => {
eprintln!("subcomando desconocido: {other}");
eprintln!("válidos: list-entes, announce, power-off, reboot, suspend, invoke-echo <text>");
std::process::exit(2);
}
};
let resp = client.call(req).await?;
println!("{resp:#?}");
Ok(())
}