2a91e2b083
ci / nightly-windev (push) Has been skipped
ci / windows-x86 (push) Successful in 1m27s
ci / java (push) Successful in 2m3s
ci / portable (push) Failing after 4m10s
Pure move: cli definition, per-group handlers (session, bulk, bench, events, galaxy, smoke, batch) and shared output/parse/connect helpers now live in their own modules. No behaviour or CLI surface change; --help of all 33 commands is byte-identical, clippy clean, tests unchanged. Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
89 lines
2.8 KiB
Rust
89 lines
2.8 KiB
Rust
//! `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(())
|
|
}
|