7
7
defmodule RabbitMQ.CLI.Ctl.Commands.EnableFeatureFlagCommand do
8
8
@ behaviour RabbitMQ.CLI.CommandBehaviour
9
9
10
- def merge_defaults ( args , opts ) , do: { args , opts }
10
+ def switches ( ) , do: [ force: :boolean ]
11
+ def aliases ( ) , do: [ f: :force ]
11
12
12
- def validate ( [ ] , _ ) , do: { :validation_failure , :not_enough_args }
13
- def validate ( [ _ | _ ] = args , _ ) when length ( args ) > 1 , do: { :validation_failure , :too_many_args }
13
+ def merge_defaults ( args , opts ) , do: { args , Map . merge ( % { force: false } , opts ) }
14
14
15
- def validate ( [ "" ] , _ ) ,
15
+ def validate ( [ ] , _opts ) , do: { :validation_failure , :not_enough_args }
16
+ def validate ( [ _ | _ ] = args , _opts ) when length ( args ) > 1 , do: { :validation_failure , :too_many_args }
17
+
18
+ def validate ( [ "" ] , _opts ) ,
16
19
do: { :validation_failure , { :bad_argument , "feature_flag cannot be an empty string." } }
17
20
18
- def validate ( [ _ ] , _ ) , do: :ok
21
+ def validate ( [ _ ] , _opts ) , do: :ok
19
22
20
23
use RabbitMQ.CLI.Core.RequiresRabbitAppRunning
21
24
@@ -29,32 +32,45 @@ defmodule RabbitMQ.CLI.Ctl.Commands.EnableFeatureFlagCommand do
29
32
end
30
33
end
31
34
32
- def run ( [ feature_flag ] , % { node: node_name } ) do
33
- case :rabbit_misc . rpc_call ( node_name , :rabbit_feature_flags , :enable , [
34
- String . to_atom ( feature_flag )
35
- ] ) do
36
- # Server does not support feature flags, consider none are available.
37
- # See rabbitmq/rabbitmq-cli#344 for context. MK.
38
- { :badrpc , { :EXIT , { :undef , _ } } } -> { :error , :unsupported }
39
- { :badrpc , _ } = err -> err
40
- other -> other
35
+ def run ( [ feature_flag ] , % { node: node_name , force: force } ) do
36
+ case { force , :rabbit_misc . rpc_call ( node_name , :rabbit_feature_flags , :get_stability , [
37
+ String . to_atom ( feature_flag )
38
+ ] ) } do
39
+ { _ , { :badrpc , { :EXIT , { :undef , _ } } } } -> { :error , :unsupported }
40
+ { _ , { :badrpc , _ } = err } -> err
41
+ { false , :experimental } ->
42
+ IO . puts ( "Feature flag #{ feature_flag } is experimental and requires --force to enable it." )
43
+ _ ->
44
+ case :rabbit_misc . rpc_call ( node_name , :rabbit_feature_flags , :enable , [
45
+ String . to_atom ( feature_flag )
46
+ ] ) do
47
+ # Server does not support feature flags, consider none are available.
48
+ # See rabbitmq/rabbitmq-cli#344 for context. MK.
49
+ { :badrpc , { :EXIT , { :undef , _ } } } -> { :error , :unsupported }
50
+ { :badrpc , _ } = err -> err
51
+ other -> other
52
+ end
41
53
end
42
54
end
43
55
44
56
def output ( { :error , :unsupported } , % { node: node_name } ) do
45
57
{ :error , RabbitMQ.CLI.Core.ExitCodes . exit_usage ( ) ,
46
- "This feature flag is not supported by node #{ node_name } " }
58
+ "This feature flag is not supported by node #{ node_name } " }
47
59
end
48
60
49
61
use RabbitMQ.CLI.DefaultOutput
50
62
51
- def usage , do: "enable_feature_flag <all | feature_flag>"
63
+ def usage , do: "enable_feature_flag [--force] <all | feature_flag>"
52
64
53
65
def usage_additional ( ) do
54
66
[
55
67
[
56
68
"<feature_flag>" ,
57
69
"name of the feature flag to enable, or \" all\" to enable all supported flags"
70
+ ] ,
71
+ [
72
+ "--force" ,
73
+ "required to enable experimental feature flags (make sure you understand the risks!))"
58
74
]
59
75
]
60
76
end
0 commit comments