summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/bin/cloudmqtt-test-client.rs42
1 files changed, 26 insertions, 16 deletions
diff --git a/src/bin/cloudmqtt-test-client.rs b/src/bin/cloudmqtt-test-client.rs
index 588c0e9..36f2d60 100644
--- a/src/bin/cloudmqtt-test-client.rs
+++ b/src/bin/cloudmqtt-test-client.rs
@@ -25,7 +25,7 @@ fn print_error_and_quit(e: String) -> ! {
#[derive(clap::Parser, Debug)]
struct Args {
#[command(subcommand)]
- command: Command,
+ command: Option<Command>,
}
#[derive(clap::Subcommand, Debug)]
@@ -47,23 +47,29 @@ enum Command {
#[tokio::main]
async fn main() {
- let (client_duplex, server_duplex) = tokio::io::duplex(512);
-
- let (mut read_dup, mut write_dup) = tokio::io::split(server_duplex);
-
- tokio::spawn(async move { tokio::io::copy(&mut tokio::io::stdin(), &mut write_dup).await });
- tokio::spawn(async move { tokio::io::copy(&mut read_dup, &mut tokio::io::stdout()).await });
-
let args = {
- std::env::args()
+ match std::env::args()
.skip(1)
.collect::<String>()
.split("----")
.map(|els| Args::try_parse_from(els.split(' ')))
.collect::<Result<Vec<Args>, _>>()
- .expect("Parsing Arguments failed")
+ {
+ Ok(args) => args,
+ Err(e) => {
+ eprintln!("{}", e);
+ exit(1)
+ }
+ }
};
+ let (client_duplex, server_duplex) = tokio::io::duplex(512);
+
+ let (mut read_dup, mut write_dup) = tokio::io::split(server_duplex);
+
+ tokio::spawn(async move { tokio::io::copy(&mut tokio::io::stdin(), &mut write_dup).await });
+ tokio::spawn(async move { tokio::io::copy(&mut read_dup, &mut tokio::io::stdout()).await });
+
let client = MqttClient::connect_v3_duplex(
client_duplex,
MqttConnectionParams {
@@ -94,25 +100,25 @@ async fn main() {
for arg in args {
match arg.command {
- Command::Quit => {}
- Command::Subscribe { topic } => {
+ Some(Command::Quit) => {}
+ Some(Command::Subscribe { topic }) => {
let subscription_requests = [MSubscriptionRequest {
topic: MString { value: &topic },
qos: MQualityOfService::AtMostOnce, // TODO
}];
client.subscribe(&subscription_requests).await.unwrap();
}
- Command::SendToTopic {
+ Some(Command::SendToTopic {
topic: _,
qos: _,
message: _,
- } => {
+ }) => {
unimplemented!()
}
- Command::ExpectOnTopic {
+ Some(Command::ExpectOnTopic {
topic: expected_topic,
qos: expected_qos,
- } => {
+ }) => {
let packet = match packet_stream.next().await {
Some(Ok(packet)) => packet,
None => {
@@ -147,6 +153,10 @@ async fn main() {
break;
}
}
+
+ None => {
+ // no command, doing nothing
+ }
}
}