diff options
| author | Michael Klishin <mklishin@pivotal.io> | 2016-03-25 01:28:51 +0300 |
|---|---|---|
| committer | Michael Klishin <mklishin@pivotal.io> | 2016-03-25 01:28:51 +0300 |
| commit | 58b0895f70ef7d39c9534c8158db65eac1662611 (patch) | |
| tree | aa25a1db6175b48cd6a8b042aba490ffbdbc0746 | |
| parent | ac9bafa4d53f72e57ccc45ad5088869093c89c13 (diff) | |
| parent | 397cd1e18379eca9222aa925ab9013abfa7181bd (diff) | |
| download | rabbitmq-server-git-58b0895f70ef7d39c9534c8158db65eac1662611.tar.gz | |
Merge branch 'stable'
| -rw-r--r-- | src/rabbit_cli.erl | 27 | ||||
| -rw-r--r-- | src/rabbit_control_main.erl | 5 |
2 files changed, 27 insertions, 5 deletions
diff --git a/src/rabbit_cli.erl b/src/rabbit_cli.erl index 086f88d9f6..4151504956 100644 --- a/src/rabbit_cli.erl +++ b/src/rabbit_cli.erl @@ -18,17 +18,19 @@ -include("rabbit_cli.hrl"). -export([main/3, start_distribution/0, start_distribution/1, - parse_arguments/4, rpc_call/4, rpc_call/5, rpc_call/7]). + parse_arguments/4, filter_opts/2, + rpc_call/4, rpc_call/5, rpc_call/7]). %%---------------------------------------------------------------------------- -ifdef(use_specs). +-type(option_name() :: string()). +-type(option_value() :: string() | node() | boolean()). -type(optdef() :: flag | {option, string()}). --type(parse_result() :: {'ok', {atom(), [{string(), string()}], [string()]}} | +-type(parse_result() :: {'ok', {atom(), [{option_name(), option_value()}], [string()]}} | 'no_command'). - -spec(main/3 :: (fun (([string()], string()) -> parse_result()), fun ((atom(), atom(), [any()], [any()]) -> any()), atom()) -> no_return()). @@ -38,6 +40,9 @@ -spec(parse_arguments/4 :: ([{atom(), [{string(), optdef()}]} | atom()], [{string(), optdef()}], string(), [string()]) -> parse_result()). + +-spec(filter_opts/2 :: ([{option_name(), option_value()}], [option_name()]) -> [boolean()]). + -spec(rpc_call/4 :: (node(), atom(), atom(), [any()]) -> any()). -spec(rpc_call/5 :: (node(), atom(), atom(), [any()], number()) -> any()). -spec(rpc_call/7 :: (node(), atom(), atom(), [any()], reference(), pid(), @@ -244,6 +249,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) + end. + %%---------------------------------------------------------------------------- fmt_stderr(Format, Args) -> rabbit_misc:format_stderr(Format ++ "~n", Args). diff --git a/src/rabbit_control_main.erl b/src/rabbit_control_main.erl index 5fcf042893..6f99ec903c 100644 --- a/src/rabbit_control_main.erl +++ b/src/rabbit_control_main.erl @@ -73,7 +73,7 @@ {clear_policy, [?VHOST_DEF]}, {list_policies, [?VHOST_DEF]}, - {list_queues, [?VHOST_DEF]}, + {list_queues, [?VHOST_DEF, ?OFFLINE_DEF, ?ONLINE_DEF]}, {list_exchanges, [?VHOST_DEF]}, {list_bindings, [?VHOST_DEF]}, {list_connections, [?VHOST_DEF]}, @@ -610,10 +610,11 @@ 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]}, + call(Node, {rabbit_amqqueue, info_all, [VHostArg, ArgAtoms, Online, Offline]}, ArgAtoms, Timeout); action(list_exchanges, Node, Args, Opts, Inform, Timeout) -> |
