Skip to content

Commit efa7ce9

Browse files
Breaking change: use --snake-case for arguments
unlike the original rabbitmqadmin v1, which used --lower_case. That is, with this change, --auto_delete becomes --auto-delete on the command line. --snake-case is more typical than --lower_case, at least that's how I see it.
1 parent c356cf6 commit efa7ce9

File tree

6 files changed

+44
-60
lines changed

6 files changed

+44
-60
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ rabbitmqadmin --vhost "events" declare queue --name "target.stream.name" --type
195195
```
196196

197197
```shell
198-
rabbitmqadmin --vhost "events" declare queue --name "target.classic.queue.name" --type "classic" --durable false --auto_delete true
198+
rabbitmqadmin --vhost "events" declare queue --name "target.classic.queue.name" --type "classic" --durable false --auto-delete true
199199
```
200200

201201
### Delete a queue

src/cli.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ fn declare_subcommands() -> [Command; 11] {
347347
.arg(
348348
Arg::new("password_hash")
349349
.help("salted password hash, see https://rabbitmq.com/docs/passwords")
350-
.long("password_hash")
350+
.long("password-hash")
351351
.required(false)
352352
.default_value(""),
353353
)
@@ -439,7 +439,7 @@ fn declare_subcommands() -> [Command; 11] {
439439
)
440440
.arg(
441441
Arg::new("auto_delete")
442-
.long("auto_delete")
442+
.long("auto-delete")
443443
.help("should it be deleted when the last consumer disconnects")
444444
.required(false)
445445
.value_parser(clap::value_parser!(bool)),
@@ -477,7 +477,7 @@ fn declare_subcommands() -> [Command; 11] {
477477
)
478478
.arg(
479479
Arg::new("auto_delete")
480-
.long("auto_delete")
480+
.long("auto-delete")
481481
.help("should it be deleted when the last queue is unbound")
482482
.required(false)
483483
.value_parser(clap::value_parser!(bool)),
@@ -501,7 +501,7 @@ fn declare_subcommands() -> [Command; 11] {
501501
)
502502
.arg(
503503
Arg::new("destination_type")
504-
.long("destination_type")
504+
.long("destination-type")
505505
.help("destination type: exchange or queue")
506506
.required(true)
507507
.value_parser(clap::value_parser!(BindingDestinationType)),
@@ -514,7 +514,7 @@ fn declare_subcommands() -> [Command; 11] {
514514
)
515515
.arg(
516516
Arg::new("routing_key")
517-
.long("routing_key")
517+
.long("routing-key")
518518
.help("routing key")
519519
.required(true),
520520
)
@@ -560,7 +560,7 @@ fn declare_subcommands() -> [Command; 11] {
560560
.required(true),
561561
)
562562
.arg(
563-
Arg::new("apply-to")
563+
Arg::new("apply_to")
564564
.long("apply-to")
565565
.help("entities to apply to (queues, classic_queues, quorum_queues, streams, exchanges, all)")
566566
.required(true),
@@ -594,7 +594,7 @@ fn declare_subcommands() -> [Command; 11] {
594594
.required(true),
595595
)
596596
.arg(
597-
Arg::new("apply-to")
597+
Arg::new("apply_to")
598598
.long("apply-to")
599599
.help("entities to apply to (queues, classic_queues, quorum_queues, streams, exchanges, all)")
600600
.required(true),
@@ -736,7 +736,7 @@ fn delete_subcommands() -> [Command; 11] {
736736
)
737737
.arg(
738738
Arg::new("destination_type")
739-
.long("destination_type")
739+
.long("destination-type")
740740
.help("destination type: exchange or queue")
741741
.required(true),
742742
)
@@ -748,7 +748,7 @@ fn delete_subcommands() -> [Command; 11] {
748748
)
749749
.arg(
750750
Arg::new("routing_key")
751-
.long("routing_key")
751+
.long("routing-key")
752752
.help("routing key")
753753
.required(true),
754754
)
@@ -918,7 +918,7 @@ pub fn publish_subcommands() -> [Command; 1] {
918918
[Command::new("message")
919919
.about("Publishes a message to an exchange")
920920
.arg(
921-
Arg::new("routing-key")
921+
Arg::new("routing_key")
922922
.short('k')
923923
.long("routing-key")
924924
.required(false)
@@ -970,7 +970,7 @@ pub fn get_subcommands() -> [Command; 1] {
970970
.help("Maximum number of messages to consume"),
971971
)
972972
.arg(
973-
Arg::new("ack-mode")
973+
Arg::new("ack_mode")
974974
.short('a')
975975
.long("ack-mode")
976976
.required(false)

src/commands.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ pub fn declare_user(client: APIClient, command_args: &ArgMatches) -> ClientResul
319319
if password.is_empty() && provided_hash.is_empty()
320320
|| !password.is_empty() && !provided_hash.is_empty()
321321
{
322-
eprintln!("Please provide either --password or --password_hash");
322+
eprintln!("Please provide either --password or --password-hash");
323323
process::exit(1)
324324
}
325325

@@ -617,7 +617,7 @@ pub fn publish_message(
617617
command_args: &ArgMatches,
618618
) -> ClientResult<responses::MessageRouted> {
619619
let exchange = command_args.get_one::<String>("exchange").unwrap();
620-
let routing_key = command_args.get_one::<String>("routing-key").unwrap();
620+
let routing_key = command_args.get_one::<String>("routing_key").unwrap();
621621
let payload = command_args.get_one::<String>("payload").unwrap();
622622
let properties = command_args.get_one::<String>("properties").unwrap();
623623
let parsed_properties = serde_json::from_str::<requests::MessageProperties>(properties)
@@ -636,6 +636,6 @@ pub fn get_messages(
636636
) -> ClientResult<Vec<responses::GetMessage>> {
637637
let queue = command_args.get_one::<String>("queue").unwrap();
638638
let count = command_args.get_one::<String>("count").unwrap();
639-
let ack_mode = command_args.get_one::<String>("ack-mode").unwrap();
639+
let ack_mode = command_args.get_one::<String>("ack_mode").unwrap();
640640
client.get_messages(vhost, queue, count.parse::<u32>().unwrap(), ack_mode)
641641
}

tests/combined_integration_tests.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ fn combined_integration_test4() -> Result<(), Box<dyn std::error::Error>> {
123123
"fanout",
124124
"--durable",
125125
"true",
126-
"--auto_delete",
126+
"--auto-delete",
127127
"false",
128128
]);
129129
run_succeeds([
@@ -141,7 +141,7 @@ fn combined_integration_test4() -> Result<(), Box<dyn std::error::Error>> {
141141
"quorum",
142142
"--durable",
143143
"true",
144-
"--auto_delete",
144+
"--auto-delete",
145145
"false",
146146
]);
147147
run_succeeds([
@@ -159,7 +159,7 @@ fn combined_integration_test4() -> Result<(), Box<dyn std::error::Error>> {
159159
"quorum",
160160
"--durable",
161161
"true",
162-
"--auto_delete",
162+
"--auto-delete",
163163
"false",
164164
]);
165165
run_succeeds([
@@ -173,11 +173,11 @@ fn combined_integration_test4() -> Result<(), Box<dyn std::error::Error>> {
173173
"binding",
174174
"--source",
175175
x,
176-
"--destination_type",
176+
"--destination-type",
177177
"queue",
178178
"--destination",
179179
q,
180-
"--routing_key",
180+
"--routing-key",
181181
"rk",
182182
]);
183183

@@ -194,11 +194,11 @@ fn combined_integration_test4() -> Result<(), Box<dyn std::error::Error>> {
194194
"binding",
195195
"--source",
196196
x,
197-
"--destination_type",
197+
"--destination-type",
198198
"queue",
199199
"--destination",
200200
q,
201-
"--routing_key",
201+
"--routing-key",
202202
"rk",
203203
]);
204204
run_succeeds(["-V", vh, "delete", "exchange", "--name", x]);

tests/list_bindings_tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ fn test_list_bindings() -> Result<(), Box<dyn std::error::Error>> {
5050
"binding",
5151
"--source",
5252
"amq.direct",
53-
"--destination_type",
53+
"--destination-type",
5454
"queue",
5555
"--destination",
5656
q1,
57-
"--routing_key",
57+
"--routing-key",
5858
"routing_key_queue",
5959
]);
6060

@@ -66,11 +66,11 @@ fn test_list_bindings() -> Result<(), Box<dyn std::error::Error>> {
6666
"binding",
6767
"--source",
6868
"amq.direct",
69-
"--destination_type",
69+
"--destination-type",
7070
"exchange",
7171
"--destination",
7272
"amq.topic",
73-
"--routing_key",
73+
"--routing-key",
7474
"routing_key_exchange",
7575
]);
7676

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::process::Command;
21
// Copyright (C) 2023-2024 RabbitMQ Core Team ([email protected])
32
//
43
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,50 +11,35 @@ use std::process::Command;
1211
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1312
// See the License for the specific language governing permissions and
1413
// limitations under the License.
15-
use assert_cmd::prelude::*;
1614
use predicates::prelude::*;
1715

16+
mod test_helpers;
17+
use crate::test_helpers::*;
18+
1819
#[test]
1920
fn test_messages() -> Result<(), Box<dyn std::error::Error>> {
2021
// declare a new queue
21-
let mut cmd = Command::cargo_bin("rabbitmqadmin")?;
22-
cmd.arg("declare")
23-
.arg("queue")
24-
.arg("--name")
25-
.arg("publish_consume")
26-
.arg("--type")
27-
.arg("classic");
28-
cmd.assert().success();
22+
let q = "publish_consume";
23+
run_succeeds(["declare", "queue", "--name", q, "--type", "classic"]);
2924

3025
// publish a message
31-
let mut cmd = Command::cargo_bin("rabbitmqadmin")?;
32-
cmd.arg("publish")
33-
.arg("message")
34-
.arg("--routing-key")
35-
.arg("publish_consume")
36-
.arg("--payload")
37-
.arg("test_messages_1")
38-
.arg("--properties")
39-
.arg("{\"timestamp\": 1234, \"message_id\": \"foo\"}");
40-
cmd.assert().success();
26+
let payload = "test_messages_1";
27+
run_succeeds([
28+
"publish",
29+
"message",
30+
"--routing-key",
31+
q,
32+
"--payload",
33+
payload,
34+
"--properties",
35+
"{\"timestamp\": 1234, \"message_id\": \"foo\"}",
36+
]);
4137

4238
// consume a message
43-
let mut cmd = Command::cargo_bin("rabbitmqadmin")?;
44-
cmd.arg("get")
45-
.arg("messages")
46-
.arg("--queue")
47-
.arg("publish_consume");
48-
cmd.assert()
49-
.success()
50-
.stdout(predicate::str::contains("test_messages_1"));
39+
run_succeeds(["get", "messages", "--queue", q]).stdout(predicate::str::contains(payload));
5140

5241
// delete the test queue
53-
let mut cmd = Command::cargo_bin("rabbitmqadmin")?;
54-
cmd.arg("delete")
55-
.arg("queue")
56-
.arg("--name")
57-
.arg("publish_consume");
58-
cmd.assert().success();
42+
run_succeeds(["delete", "queue", "--name", q]);
5943

6044
Ok(())
6145
}

0 commit comments

Comments
 (0)