summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandru Scvortov <alexandru@rabbitmq.com>2011-09-22 18:39:18 +0100
committerAlexandru Scvortov <alexandru@rabbitmq.com>2011-09-22 18:39:18 +0100
commit3bb75c177cfbbef998dab297682ba8e1468b6add (patch)
treefa028e4436689b85b57de529a65ed69c2a7bd8d0
parenta05e7717539d39bedff3e17b03c87845881fc600 (diff)
downloadrabbitmq-server-git-3bb75c177cfbbef998dab297682ba8e1468b6add.tar.gz
-e and -E filter by enabled status
-rw-r--r--docs/rabbitmq-plugins.1.xml17
-rw-r--r--src/rabbit_plugins.erl23
2 files changed, 35 insertions, 5 deletions
diff --git a/docs/rabbitmq-plugins.1.xml b/docs/rabbitmq-plugins.1.xml
index a04dccde57..49fa709a8f 100644
--- a/docs/rabbitmq-plugins.1.xml
+++ b/docs/rabbitmq-plugins.1.xml
@@ -60,7 +60,7 @@
<variablelist>
<varlistentry>
- <term><cmdsynopsis><command>list</command> <arg choice="opt">-v</arg> <arg choice="opt"><replaceable>pattern</replaceable></arg></cmdsynopsis></term>
+ <term><cmdsynopsis><command>list</command> <arg choice="opt">-v</arg> <arg choice="opt">-E</arg> <arg choice="opt">-e</arg> <arg choice="opt"><replaceable>pattern</replaceable></arg></cmdsynopsis></term>
<listitem>
<variablelist>
<varlistentry>
@@ -68,6 +68,16 @@
<listitem><para>Show all plugin details.</para></listitem>
</varlistentry>
<varlistentry>
+ <term>-E</term>
+ <listitem><para>Show only explicitly enabled
+ plugins.</para></listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>-e</term>
+ <listitem><para>Show only explicitly or implicitly
+ enabled plugins.</para></listitem>
+ </varlistentry>
+ <varlistentry>
<term>pattern</term>
<listitem><para>Pattern to filter the plugin names by.</para></listitem>
</varlistentry>
@@ -94,6 +104,11 @@
This command lists all the plugins available, but does not
display plugins whose name does not contain "management".
</para>
+ <screen role="example">rabbitmq-plugins list -e rabbit</screen>
+ <para role="example">
+ This command lists all implicitly or explicitly enabled
+ rabbit plugins.
+ </para>
</listitem>
</varlistentry>
diff --git a/src/rabbit_plugins.erl b/src/rabbit_plugins.erl
index fc59846e0f..3264925e18 100644
--- a/src/rabbit_plugins.erl
+++ b/src/rabbit_plugins.erl
@@ -21,6 +21,8 @@
lookup_plugins/2, calculate_required_plugins/2]).
-define(VERBOSE_OPT, "-v").
+-define(ENABLED_OPT, "-E").
+-define(ENABLED_ALL_OPT, "-e").
%%----------------------------------------------------------------------------
@@ -39,7 +41,9 @@ start() ->
{ok, [[PluginsDistDir|_]|_]} = init:get_argument(plugins_dist_dir),
put(plugins_dist_dir, PluginsDistDir),
{[Command0 | Args], Opts} =
- case rabbit_misc:get_options([{flag, ?VERBOSE_OPT}],
+ case rabbit_misc:get_options([{flag, ?VERBOSE_OPT},
+ {flag, ?ENABLED_OPT},
+ {flag, ?ENABLED_ALL_OPT}],
init:get_plain_arguments()) of
{[], _Opts} -> usage();
CmdArgsAndOpts -> CmdArgsAndOpts
@@ -76,7 +80,7 @@ usage() ->
action(list, [], Opts) ->
action(list, [".*"], Opts);
action(list, [Pat], Opts) ->
- format_plugins(Pat, proplists:get_bool(?VERBOSE_OPT, Opts));
+ format_plugins(Pat, Opts);
action(enable, ToEnable0, _Opts) ->
AllPlugins = find_plugins(),
@@ -201,7 +205,11 @@ parse_binary(Bin) ->
end.
%% Pretty print a list of plugins.
-format_plugins(Pattern, Verbose) ->
+format_plugins(Pattern, Opts) ->
+ Verbose = proplists:get_bool(?VERBOSE_OPT, Opts),
+ OnlyEnabled = proplists:get_bool(?ENABLED_OPT, Opts),
+ OnlyEnabledAll = proplists:get_bool(?ENABLED_ALL_OPT, Opts),
+
AvailablePlugins = find_plugins(),
EnabledExplicitly = read_enabled_plugins(),
EnabledImplicitly =
@@ -210,7 +218,14 @@ format_plugins(Pattern, Verbose) ->
{ok, RE} = re:compile(Pattern),
Plugins = [ Plugin ||
Plugin = #plugin{name = Name} <- AvailablePlugins,
- re:run(atom_to_list(Name), RE, [{capture, none}]) =:= match],
+ re:run(atom_to_list(Name), RE, [{capture, none}]) =:= match,
+ if OnlyEnabled -> lists:member(Name, EnabledExplicitly);
+ true -> true
+ end,
+ if OnlyEnabledAll -> lists:member(Name, EnabledImplicitly) or
+ lists:member(Name, EnabledExplicitly);
+ true -> true
+ end],
MaxWidth = lists:max([length(atom_to_list(Name)) ||
#plugin{name = Name} <- Plugins] ++ [0]),
[ format_plugin(P, EnabledExplicitly, EnabledImplicitly, Verbose, MaxWidth) ||