Skip to content

Commit

Permalink
Closes #41
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelklishin committed Dec 29, 2024
1 parent 06f9ebd commit 348760e
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@ pub fn parser() -> Command {
))
.subcommand_value_name("definitions")
.subcommands(import_subcommands()),
Command::new("feature_flags")
.about("operations on feature flags")
.after_long_help(color_print::cformat!(
"<bold>Doc guide</bold>: {}",
FEATURE_FLAG_GUIDE_URL
))
.subcommand_value_name("feature flag")
.subcommands(feature_flags_subcommands()),
Command::new("publish")
.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>."))
.after_long_help(color_print::cformat!("<bold>Doc guide</bold>: {}", PUBLISHER_GUIDE_URL))
Expand Down Expand Up @@ -1003,6 +1011,37 @@ fn import_subcommands() -> [Command; 1] {
)]
}

pub fn feature_flags_subcommands() -> [Command; 3] {
let list_cmd = Command::new("list")
.long_about("Lists feature flags and their cluster state")
.after_long_help(color_print::cformat!(
"<bold>Doc guide</bold>: {}",
FEATURE_FLAG_GUIDE_URL
));

let enable_cmd = Command::new("enable")
.long_about("Enables a feature flag")
.after_long_help(color_print::cformat!(
"<bold>Doc guide</bold>: {}",
FEATURE_FLAG_GUIDE_URL
))
.arg(
Arg::new("name")
.long("name")
.help("feature flag name (identifier)")
.required(true),
);

let enable_all_cmd = Command::new("enable_all")
.long_about("Enables all stable feature flags")
.after_long_help(color_print::cformat!(
"<bold>Doc guide</bold>: {}",
FEATURE_FLAG_GUIDE_URL
));

[list_cmd, enable_cmd, enable_all_cmd]
}

pub fn publish_subcommands() -> [Command; 1] {
[Command::new("message")
.about("Publishes a message to an exchange")
Expand Down
9 changes: 9 additions & 0 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ pub fn list_feature_flags(client: APIClient) -> ClientResult<FeatureFlagList> {
client.list_feature_flags()
}

pub fn enable_feature_flag(client: APIClient, command_args: &ArgMatches) -> ClientResult<()> {
let name = command_args.get_one::<String>("name").cloned().unwrap();
client.enable_feature_flag(&name)
}

pub fn enable_all_stable_feature_flags(client: APIClient) -> ClientResult<()> {
client.enable_all_stable_feature_flags()
}

pub fn list_deprecated_features(
client: APIClient,
) -> ClientResult<responses::DeprecatedFeatureList> {
Expand Down
12 changes: 12 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,18 @@ fn dispatch_subcommand(
let result = commands::import_definitions(client, command_args);
res_handler.no_output_on_success(result);
}
("feature_flags", "list") => {
let result = commands::list_feature_flags(client);
res_handler.tabular_result(result.map(|val| val.0))
}
("feature_flags", "enable") => {
let result = commands::enable_feature_flag(client, command_args);
res_handler.no_output_on_success(result);
}
("feature_flags", "enable_all") => {
let result = commands::enable_all_stable_feature_flags(client);
res_handler.no_output_on_success(result);
}
("publish", "message") => {
let result = commands::publish_message(client, &vhost, command_args);
res_handler.single_value_result(result)
Expand Down
38 changes: 38 additions & 0 deletions tests/feature_flag_management_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (C) 2023-2024 RabbitMQ Core Team (teamrabbitmq@gmail.com)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use predicates::prelude::*;

mod test_helpers;
use crate::test_helpers::*;

#[test]
fn test_enable_a_feature_flag() -> Result<(), Box<dyn std::error::Error>> {
let ff_name = "detailed_queues_endpoint";

run_succeeds(["feature_flags", "enable", "--name", ff_name]);
run_succeeds(["feature_flags", "list"]).stdout(predicate::str::contains(ff_name));

Ok(())
}

#[test]
fn test_enable_all_stable_feature_flags() -> Result<(), Box<dyn std::error::Error>> {
let ff_name = "rabbitmq_4.0.0";

run_succeeds(["feature_flags", "enable_all"]);
run_succeeds(["feature_flags", "list"]).stdout(predicate::str::contains(ff_name));

Ok(())
}

0 comments on commit 348760e

Please sign in to comment.