Skip to content

Commit 8d35a1f

Browse files
New command group: channels
1 parent 941fb9a commit 8d35a1f

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Enhancements
66

77
* `connections` is a new command group for operations on connections
8+
* `channels` is a new command group for operations on channels
89
* `policies set` and `policies update` are two new aliases for `policies declare`. The former follows the naming
910
used by `rabbitmqctl` and the latter reflects the fact that the command can be used to update an existing policy,
1011
in particular, to override its definition

src/cli.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ pub fn parser(pre_flight_settings: PreFlightSettings) -> Command {
5151
.infer_long_args(pre_flight_settings.infer_long_options)
5252
.subcommand_value_name("binding")
5353
.subcommands(binding_subcommands(pre_flight_settings.clone()));
54+
let channels_group = Command::new("channels")
55+
.about("Operations on channels")
56+
.infer_subcommands(pre_flight_settings.infer_subcommands)
57+
.infer_long_args(pre_flight_settings.infer_long_options)
58+
.subcommands(channels_subcommands(pre_flight_settings.clone()));
5459
let close_group = Command::new("close")
5560
.about("Closes connections")
5661
.infer_subcommands(pre_flight_settings.infer_subcommands)
@@ -287,6 +292,7 @@ pub fn parser(pre_flight_settings: PreFlightSettings) -> Command {
287292

288293
let command_groups = [
289294
bindings_group,
295+
channels_group,
290296
close_group,
291297
connections_group,
292298
declare_group,
@@ -1848,6 +1854,17 @@ fn close_subcommands(pre_flight_settings: PreFlightSettings) -> [Command; 2] {
18481854
.map(|cmd| cmd.infer_long_args(pre_flight_settings.infer_long_options))
18491855
}
18501856

1857+
fn channels_subcommands(pre_flight_settings: PreFlightSettings) -> [Command; 1] {
1858+
let list_cmd = Command::new("list")
1859+
.long_about("Lists all channels across all virtual hosts")
1860+
.after_help(color_print::cformat!(
1861+
"<bold>Doc guide</bold>: {}",
1862+
"https://www.rabbitmq.com/docs/channels"
1863+
));
1864+
1865+
[list_cmd].map(|cmd| cmd.infer_long_args(pre_flight_settings.infer_long_options))
1866+
}
1867+
18511868
fn connections_subcommands(pre_flight_settings: PreFlightSettings) -> [Command; 4] {
18521869
let close_connection = Command::new("close")
18531870
.about("Closes a client connection")

src/main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414
#![allow(clippy::result_large_err)]
15+
#![allow(clippy::unnecessary_unwrap)]
16+
#![allow(clippy::collapsible_if)]
1517

1618
use clap::ArgMatches;
1719
use errors::CommandRunError;
@@ -291,6 +293,10 @@ fn dispatch_common_subcommand(
291293
let result = commands::list_bindings(client);
292294
res_handler.tabular_result(result)
293295
}
296+
("channels", "list") => {
297+
let result = commands::list_channels(client);
298+
res_handler.tabular_result(result)
299+
}
294300
("close", "connection") => {
295301
let result = commands::close_connection(client, second_level_args);
296302
res_handler.no_output_on_success(result);

tests/channels_tests.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (C) 2023-2025 RabbitMQ Core Team ([email protected])
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
mod test_helpers;
16+
use crate::test_helpers::*;
17+
18+
#[test]
19+
fn test_list_channels1() -> Result<(), Box<dyn std::error::Error>> {
20+
run_succeeds(["channels", "list"]);
21+
22+
Ok(())
23+
}
24+
25+
#[test]
26+
fn test_list_channels2() -> Result<(), Box<dyn std::error::Error>> {
27+
run_succeeds(["list", "channels"]);
28+
29+
Ok(())
30+
}

0 commit comments

Comments
 (0)