summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2023-01-19 09:45:11 +0000
committerGitHub <noreply@github.com>2023-01-19 09:45:11 +0000
commita6c2f879a1e9d516ba31ff8db323985e6b294313 (patch)
tree1859574c8a6cc876608b567f72f455989d4a8448
parentda547b75dca31f3966fa24e9e78b393288a8741b (diff)
parent99a0e80c89079302e1582f560ebc91dcc2e0acba (diff)
Merge #149
149: Fix argparsing in test client binary r=TheNeikos a=matthiasbeyer Extracted from #133. This patchset contains fixes for the test client binary argparsing code. Co-authored-by: Matthias Beyer <mail@beyermatthias.de>
-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
+ }
}
}