65 lines
1.4 KiB
Rust
65 lines
1.4 KiB
Rust
use std::process::ExitCode;
|
|
|
|
use clap::{Parser, Subcommand};
|
|
use mxgateway_client::{CLIENT_VERSION, GATEWAY_PROTOCOL_VERSION, WORKER_PROTOCOL_VERSION};
|
|
use serde_json::json;
|
|
|
|
#[derive(Debug, Parser)]
|
|
#[command(name = "mxgw")]
|
|
#[command(about = "MXAccess Gateway Rust test CLI")]
|
|
struct Cli {
|
|
#[command(subcommand)]
|
|
command: Command,
|
|
}
|
|
|
|
#[derive(Debug, Subcommand)]
|
|
enum Command {
|
|
Version {
|
|
#[arg(long)]
|
|
json: bool,
|
|
},
|
|
}
|
|
|
|
fn main() -> ExitCode {
|
|
let cli = Cli::parse();
|
|
run(cli);
|
|
ExitCode::SUCCESS
|
|
}
|
|
|
|
fn run(cli: Cli) {
|
|
match cli.command {
|
|
Command::Version { json } => print_version(json),
|
|
}
|
|
}
|
|
|
|
fn print_version(use_json: bool) {
|
|
if use_json {
|
|
println!(
|
|
"{}",
|
|
json!({
|
|
"clientVersion": CLIENT_VERSION,
|
|
"gatewayProtocolVersion": GATEWAY_PROTOCOL_VERSION,
|
|
"workerProtocolVersion": WORKER_PROTOCOL_VERSION,
|
|
})
|
|
);
|
|
return;
|
|
}
|
|
|
|
println!("mxgw {CLIENT_VERSION}");
|
|
println!("gateway protocol {GATEWAY_PROTOCOL_VERSION}");
|
|
println!("worker protocol {WORKER_PROTOCOL_VERSION}");
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use clap::Parser;
|
|
|
|
use super::Cli;
|
|
|
|
#[test]
|
|
fn parses_version_json_command() {
|
|
let parsed = Cli::try_parse_from(["mxgw", "version", "--json"]);
|
|
assert!(parsed.is_ok());
|
|
}
|
|
}
|