summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rabbit_cli.erl35
-rw-r--r--src/rabbit_control_main.erl21
2 files changed, 32 insertions, 24 deletions
diff --git a/src/rabbit_cli.erl b/src/rabbit_cli.erl
index c8f704dc15..c0e5c93247 100644
--- a/src/rabbit_cli.erl
+++ b/src/rabbit_cli.erl
@@ -18,7 +18,7 @@
-include("rabbit_cli.hrl").
-export([main/3, start_distribution/0, start_distribution/1,
- parse_arguments/4, filter_opts/2,
+ parse_arguments/4, mutually_exclusive_flags/3,
rpc_call/4, rpc_call/5, rpc_call/7]).
%%----------------------------------------------------------------------------
@@ -42,8 +42,7 @@
[{string(), optdef()}], string(), [string()]) ->
parse_result().
--spec filter_opts([{option_name(), option_value()}], [option_name()]) ->
- [boolean()].
+-spec mutually_exclusive_flags([{option_name(), option_value()}], term(), [{option_name(), term()}]) -> {ok, term()} | {error, string()}.
-spec rpc_call(node(), atom(), atom(), [any()]) -> any().
-spec rpc_call(node(), atom(), atom(), [any()], number()) -> any().
@@ -266,20 +265,22 @@ process_opts(Defs, C, [A | As], Found, KVs, Outs) ->
{none, _, _} -> no_command
end.
-%% When we have a set of flags that are used for filtering, we want by
-%% default to include every such option in our output. But if a user
-%% explicitly specified any such flag, we want to include only items
-%% which he has requested.
-filter_opts(CurrentOptionValues, AllOptionNames) ->
- Explicit = lists:map(fun(OptName) ->
- proplists:get_bool(OptName, CurrentOptionValues)
- end,
- AllOptionNames),
- case lists:member(true, Explicit) of
- true ->
- Explicit;
- false ->
- lists:duplicate(length(AllOptionNames), true)
+mutually_exclusive_flags(CurrentOptionValues, Default, FlagsAndValues) ->
+ PresentFlags = lists:filtermap(fun({OptName, _} = _O) ->
+ proplists:get_bool(OptName, CurrentOptionValues)
+ end,
+ FlagsAndValues),
+ case PresentFlags of
+ [] ->
+ {ok, Default};
+ [{_, Value}] ->
+ {ok, Value};
+ _ ->
+ Names = [ [$', N, $'] || {N, _} <- PresentFlags ],
+ CommaSeparated = string:join(lists:droplast(Names), ", "),
+ AndOneMore = lists:last(Names),
+ Msg = io_lib:format("Options ~s and ~s are mutually exclusive", [CommaSeparated, AndOneMore]),
+ {error, lists:flatten(Msg)}
end.
%%----------------------------------------------------------------------------
diff --git a/src/rabbit_control_main.erl b/src/rabbit_control_main.erl
index ea9d6a2030..92898c2a2c 100644
--- a/src/rabbit_control_main.erl
+++ b/src/rabbit_control_main.erl
@@ -74,7 +74,7 @@
{clear_policy, [?VHOST_DEF]},
{list_policies, [?VHOST_DEF]},
- {list_queues, [?VHOST_DEF, ?OFFLINE_DEF, ?ONLINE_DEF]},
+ {list_queues, [?VHOST_DEF, ?OFFLINE_DEF, ?ONLINE_DEF, ?LOCAL_DEF]},
{list_exchanges, [?VHOST_DEF]},
{list_bindings, [?VHOST_DEF]},
{list_connections, [?VHOST_DEF]},
@@ -632,12 +632,19 @@ action(list_user_permissions, Node, Args = [_Username], _Opts, Inform, Timeout)
true);
action(list_queues, Node, Args, Opts, Inform, Timeout) ->
- [Online, Offline] = rabbit_cli:filter_opts(Opts, [?ONLINE_OPT, ?OFFLINE_OPT]),
- Inform("Listing queues", []),
- VHostArg = list_to_binary(proplists:get_value(?VHOST_OPT, Opts)),
- ArgAtoms = default_if_empty(Args, [name, messages]),
- call(Node, {rabbit_amqqueue, info_all, [VHostArg, ArgAtoms, Online, Offline]},
- ArgAtoms, Timeout);
+ case rabbit_cli:mutually_exclusive_flags(
+ Opts, all, [{?ONLINE_OPT, online}
+ ,{?OFFLINE_OPT, offline}
+ ,{?LOCAL_OPT, local}]) of
+ {ok, Filter} ->
+ Inform("Listing queues", []),
+ VHostArg = list_to_binary(proplists:get_value(?VHOST_OPT, Opts)),
+ ArgAtoms = default_if_empty(Args, [name, messages]),
+ call(Node, {rabbit_amqqueue, info_all, [VHostArg, ArgAtoms, Filter]},
+ ArgAtoms, Timeout);
+ {error, ErrStr} ->
+ {error_string, ErrStr}
+ end;
action(list_exchanges, Node, Args, Opts, Inform, Timeout) ->
Inform("Listing exchanges", []),