Skip to content

Commit 348760e

Browse files
Closes #41
1 parent 06f9ebd commit 348760e

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed

src/cli.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,14 @@ pub fn parser() -> Command {
240240
))
241241
.subcommand_value_name("definitions")
242242
.subcommands(import_subcommands()),
243+
Command::new("feature_flags")
244+
.about("operations on feature flags")
245+
.after_long_help(color_print::cformat!(
246+
"<bold>Doc guide</bold>: {}",
247+
FEATURE_FLAG_GUIDE_URL
248+
))
249+
.subcommand_value_name("feature flag")
250+
.subcommands(feature_flags_subcommands()),
243251
Command::new("publish")
244252
.about(color_print::cstr!("Publishes (<red>inefficiently</red>) message(s) to a queue or a stream. <bold><red>Only suitable for development and test environments</red></bold>."))
245253
.after_long_help(color_print::cformat!("<bold>Doc guide</bold>: {}", PUBLISHER_GUIDE_URL))
@@ -1003,6 +1011,37 @@ fn import_subcommands() -> [Command; 1] {
10031011
)]
10041012
}
10051013

1014+
pub fn feature_flags_subcommands() -> [Command; 3] {
1015+
let list_cmd = Command::new("list")
1016+
.long_about("Lists feature flags and their cluster state")
1017+
.after_long_help(color_print::cformat!(
1018+
"<bold>Doc guide</bold>: {}",
1019+
FEATURE_FLAG_GUIDE_URL
1020+
));
1021+
1022+
let enable_cmd = Command::new("enable")
1023+
.long_about("Enables a feature flag")
1024+
.after_long_help(color_print::cformat!(
1025+
"<bold>Doc guide</bold>: {}",
1026+
FEATURE_FLAG_GUIDE_URL
1027+
))
1028+
.arg(
1029+
Arg::new("name")
1030+
.long("name")
1031+
.help("feature flag name (identifier)")
1032+
.required(true),
1033+
);
1034+
1035+
let enable_all_cmd = Command::new("enable_all")
1036+
.long_about("Enables all stable feature flags")
1037+
.after_long_help(color_print::cformat!(
1038+
"<bold>Doc guide</bold>: {}",
1039+
FEATURE_FLAG_GUIDE_URL
1040+
));
1041+
1042+
[list_cmd, enable_cmd, enable_all_cmd]
1043+
}
1044+
10061045
pub fn publish_subcommands() -> [Command; 1] {
10071046
[Command::new("message")
10081047
.about("Publishes a message to an exchange")

src/commands.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ pub fn list_feature_flags(client: APIClient) -> ClientResult<FeatureFlagList> {
126126
client.list_feature_flags()
127127
}
128128

129+
pub fn enable_feature_flag(client: APIClient, command_args: &ArgMatches) -> ClientResult<()> {
130+
let name = command_args.get_one::<String>("name").cloned().unwrap();
131+
client.enable_feature_flag(&name)
132+
}
133+
134+
pub fn enable_all_stable_feature_flags(client: APIClient) -> ClientResult<()> {
135+
client.enable_all_stable_feature_flags()
136+
}
137+
129138
pub fn list_deprecated_features(
130139
client: APIClient,
131140
) -> ClientResult<responses::DeprecatedFeatureList> {

src/main.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,18 @@ fn dispatch_subcommand(
372372
let result = commands::import_definitions(client, command_args);
373373
res_handler.no_output_on_success(result);
374374
}
375+
("feature_flags", "list") => {
376+
let result = commands::list_feature_flags(client);
377+
res_handler.tabular_result(result.map(|val| val.0))
378+
}
379+
("feature_flags", "enable") => {
380+
let result = commands::enable_feature_flag(client, command_args);
381+
res_handler.no_output_on_success(result);
382+
}
383+
("feature_flags", "enable_all") => {
384+
let result = commands::enable_all_stable_feature_flags(client);
385+
res_handler.no_output_on_success(result);
386+
}
375387
("publish", "message") => {
376388
let result = commands::publish_message(client, &vhost, command_args);
377389
res_handler.single_value_result(result)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (C) 2023-2024 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+
use predicates::prelude::*;
16+
17+
mod test_helpers;
18+
use crate::test_helpers::*;
19+
20+
#[test]
21+
fn test_enable_a_feature_flag() -> Result<(), Box<dyn std::error::Error>> {
22+
let ff_name = "detailed_queues_endpoint";
23+
24+
run_succeeds(["feature_flags", "enable", "--name", ff_name]);
25+
run_succeeds(["feature_flags", "list"]).stdout(predicate::str::contains(ff_name));
26+
27+
Ok(())
28+
}
29+
30+
#[test]
31+
fn test_enable_all_stable_feature_flags() -> Result<(), Box<dyn std::error::Error>> {
32+
let ff_name = "rabbitmq_4.0.0";
33+
34+
run_succeeds(["feature_flags", "enable_all"]);
35+
run_succeeds(["feature_flags", "list"]).stdout(predicate::str::contains(ff_name));
36+
37+
Ok(())
38+
}

0 commit comments

Comments
 (0)