diff options
| author | Alexandru Scvortov <alexandru@rabbitmq.com> | 2011-09-14 01:17:47 +0100 |
|---|---|---|
| committer | Alexandru Scvortov <alexandru@rabbitmq.com> | 2011-09-14 01:17:47 +0100 |
| commit | 7f404a06b61373a5a8bdd853182eac212fc177b4 (patch) | |
| tree | 5d1e45a551d2d2eafa0052227bcc37c8e8a710cb /src | |
| parent | 9332d2b689eb8fcbbfc033f9fdb8222dc235bb34 (diff) | |
| download | rabbitmq-server-git-7f404a06b61373a5a8bdd853182eac212fc177b4.tar.gz | |
add a compact plugin listing option
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit_plugin.erl | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/src/rabbit_plugin.erl b/src/rabbit_plugin.erl index e63e6f55d9..399b067721 100644 --- a/src/rabbit_plugin.erl +++ b/src/rabbit_plugin.erl @@ -20,6 +20,7 @@ -export([start/0, stop/0]). -define(FORCE_OPT, "-f"). +-define(COMPACT_OPT, "-c"). -record(plugin, {name, %% atom() version, %% string() @@ -42,7 +43,8 @@ start() -> {ok, [[PluginsDir|_]|_]} = init:get_argument(plugins_dir), {ok, [[PluginsDistDir|_]|_]} = init:get_argument(plugins_dist_dir), {[Command0 | Args], Opts} = - case rabbit_misc:get_options([{flag, ?FORCE_OPT}], + case rabbit_misc:get_options([{flag, ?FORCE_OPT}, + {flag, ?COMPACT_OPT}], init:get_plain_arguments()) of {[], _Opts} -> usage(); CmdArgsAndOpts -> CmdArgsAndOpts @@ -76,8 +78,9 @@ usage() -> %%---------------------------------------------------------------------------- -action(list, [], _Opts, PluginsDir, PluginsDistDir) -> - format_plugins(PluginsDir, PluginsDistDir); +action(list, [], Opts, PluginsDir, PluginsDistDir) -> + format_plugins(PluginsDir, PluginsDistDir, + proplists:get_bool(?COMPACT_OPT, Opts)); action(enable, ToEnable0, _Opts, PluginsDir, PluginsDistDir) -> AllPlugins = find_plugins(PluginsDistDir), @@ -177,32 +180,37 @@ parse_binary(Bin) -> end. %% Pretty print a list of plugins. -format_plugins(PluginsDir, PluginsDistDir) -> +format_plugins(PluginsDir, PluginsDistDir, Compact) -> AvailablePlugins = find_plugins(PluginsDistDir), EnabledExplicitly = read_enabled_plugins(PluginsDir), EnabledPlugins = find_plugins(PluginsDir), EnabledImplicitly = plugin_names(EnabledPlugins) -- EnabledExplicitly, - [ format_plugin(Plugin, EnabledExplicitly, EnabledImplicitly) + [ format_plugin(Plugin, EnabledExplicitly, EnabledImplicitly, Compact) || Plugin <- usort_plugins(EnabledPlugins ++ AvailablePlugins)], ok. format_plugin(#plugin{name = Name, version = Version, description = Description, dependencies = Dependencies}, - EnabledExplicitly, EnabledImplicitly) -> + EnabledExplicitly, EnabledImplicitly, Compact) -> Glyph = case {lists:member(Name, EnabledExplicitly), lists:member(Name, EnabledImplicitly)} of {true, false} -> "[E]"; {false, true} -> "[e]"; - _ -> " * " + _ -> "[A]" end, - io:format("~s ~w~n", [Glyph, Name]), - io:format(" Version: \t~s~n", [Version]), - case Dependencies of - [] -> ok; - _ -> io:format(" Dependencies:\t~p~n", [Dependencies]) - end, - io:format(" Description:\t~s~n", [Description]), - io:format("~n"). + case Compact of + true -> + io:format("~s ~w-~s: ~s~n", [Glyph, Name, Version, Description]); + false -> + io:format("~s ~w~n", [Glyph, Name]), + io:format(" Version: \t~s~n", [Version]), + case Dependencies of + [] -> ok; + _ -> io:format(" Dependencies:\t~p~n", [Dependencies]) + end, + io:format(" Description:\t~s~n", [Description]), + io:format("~n") + end. usort_plugins(Plugins) -> lists:usort(fun plugins_cmp/2, Plugins). |
