//! `mxgw` — the Rust test CLI for the MXAccess Gateway. //! //! The binary wraps [`zb_mom_ww_mxgateway_client`] in a `clap`-driven command surface //! used by the cross-language smoke matrix and by developers exercising the //! gateway by hand. Every subcommand mirrors a single gateway/Galaxy RPC, //! prints either a terse line or a JSON document with `--json`, and exits //! non-zero on any failure. #![warn(missing_docs)] mod batch; mod bench; mod bulk; mod cli; mod connect; mod events; mod galaxy; mod output; mod parse; mod session; mod smoke; #[cfg(test)] mod tests; use std::process::ExitCode; use clap::Parser; use zb_mom_ww_mxgateway_client::Error; use crate::cli::{Cli, Command}; #[tokio::main] async fn main() -> ExitCode { let cli = Cli::parse(); let result = match cli.command { Command::Batch => batch::run_batch().await, command => dispatch(command).await, }; match result { Ok(()) => ExitCode::SUCCESS, Err(error) => { eprintln!("{error}"); ExitCode::FAILURE } } } /// Dispatch a parsed [`Command`] to its handler. All subcommands except /// [`Command::Batch`] are handled here; `Batch` is handled separately in /// `main` to avoid mutual recursion between `dispatch` and `run_batch`. async fn dispatch(command: Command) -> Result<(), Error> { match command { Command::Batch => { return Err(Error::InvalidArgument { name: "batch".to_owned(), detail: "batch cannot be nested inside another batch session".to_owned(), }); } Command::Galaxy(galaxy_command) => galaxy::run_galaxy(galaxy_command).await?, command @ (Command::Version { .. } | Command::Ping { .. } | Command::OpenSession { .. } | Command::CloseSession { .. } | Command::Register { .. } | Command::AddItem { .. } | Command::Advise { .. } | Command::AdviseSupervisory { .. } | Command::Unregister { .. } | Command::AuthenticateUser { .. } | Command::WriteSecured { .. } | Command::Write { .. } | Command::Write2 { .. }) => session::run(command).await?, command @ (Command::SubscribeBulk { .. } | Command::UnsubscribeBulk { .. } | Command::ReadBulk { .. } | Command::WriteBulk { .. } | Command::Write2Bulk { .. } | Command::WriteSecuredBulk { .. } | Command::WriteSecured2Bulk { .. }) => bulk::run(command).await?, command @ Command::BenchReadBulk { .. } => bench::run(command).await?, command @ (Command::StreamEvents { .. } | Command::StreamAlarms { .. } | Command::AcknowledgeAlarm { .. }) => events::run(command).await?, command @ Command::Smoke { .. } => smoke::run(command).await?, } Ok(()) }