diff options
author | Emile Joubert <emile@lshift.net> | 2008-11-23 20:23:06 +0000 |
---|---|---|
committer | Emile Joubert <emile@lshift.net> | 2008-11-23 20:23:06 +0000 |
commit | 46a0d8c35e8801f8d4e9630846cf5bd4128a1c47 (patch) | |
tree | f520154365aa4692d93d90f25107402dfc1c6ea2 | |
parent | 7cec7c133b200dad670c9884b9efac106a9f22cc (diff) | |
download | rabbitmq-server-46a0d8c35e8801f8d4e9630846cf5bd4128a1c47.tar.gz |
Guarantee order of rabbitctl result columns
Added default arguments for list_queues and list_exchanges
-rw-r--r-- | src/rabbit_control.erl | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl index c9fa6ddf..f749bb92 100644 --- a/src/rabbit_control.erl +++ b/src/rabbit_control.erl @@ -101,10 +101,11 @@ output of hostname -s is usually the correct suffix to use after the \"@\" sign. <QueueInfoItem> must be a member of the list [name, durable, auto_delete, arguments, pid, messages_ready, messages_unacknowledged, messages_uncommitted, -messages, acks_uncommitted, consumers, transactions, memory]. +messages, acks_uncommitted, consumers, transactions, memory]. (Default is +[name, messages].) <ExchangeInfoItem> must be a member of the list [name, type, durable, -auto_delete, arguments]. +auto_delete, arguments]. (Default is [name, type].) "), halt(1). @@ -194,33 +195,42 @@ action(list_vhost_users, Node, Args = [_VHostPath]) -> action(list_queues, Node, Args) -> io:format("Listing queues ...~n"), - display_info_list(rpc_call(Node, rabbit_amqqueue, info_all, [[list_to_atom(X) || X <- Args]])); + ArgAtoms = [list_to_atom(X) || X <- default_if_empty(Args, ["name", "messages"])], + display_info_list(rpc_call(Node, rabbit_amqqueue, info_all, [ArgAtoms]), ArgAtoms); action(list_exchanges, Node, Args) -> io:format("Listing exchanges ...~n"), - display_info_list(rpc_call(Node, rabbit_exchange, info_all, [[list_to_atom(X) || X <- Args]])); + ArgAtoms = [list_to_atom(X) || X <- default_if_empty(Args, ["name", "type"])], + display_info_list(rpc_call(Node, rabbit_exchange, info_all, [ArgAtoms]), ArgAtoms); action(list_bindings, _, []) -> io:format("Listing bindings ...~n"), io:format("Not implemented~n"), ok. -display_info_list(L) -> +default_if_empty(List, Default) when is_list(List) -> + case List of + [] -> Default; + _ -> List + end. + +display_info_list(Results, InfoItemArgs) when is_list(Results) -> lists:map( fun (ResultRow) -> - lists:map( - fun(ResultColumn) -> - case ResultColumn of - {name, #resource{virtual_host = VHostPath, name = Name}} -> + lists:foreach( + fun(InfoItemName) -> + {value, {InfoItemName, Res}} = lists:keysearch(InfoItemName, 1, ResultRow), + case Res of + #resource{virtual_host = VHostPath, name = Name} -> io:format("~s@~s ", [Name, VHostPath]); - {_, Res} -> + _ -> io:format("~w ", [Res]) end - end, - ResultRow), + end, + InfoItemArgs), io:nl() end, - L), + Results), ok. display_list(L) when is_list(L) -> |