diff options
| author | Alexandru Scvortov <alexandru@rabbitmq.com> | 2011-09-22 18:39:18 +0100 |
|---|---|---|
| committer | Alexandru Scvortov <alexandru@rabbitmq.com> | 2011-09-22 18:39:18 +0100 |
| commit | 3bb75c177cfbbef998dab297682ba8e1468b6add (patch) | |
| tree | fa028e4436689b85b57de529a65ed69c2a7bd8d0 /src | |
| parent | a05e7717539d39bedff3e17b03c87845881fc600 (diff) | |
| download | rabbitmq-server-git-3bb75c177cfbbef998dab297682ba8e1468b6add.tar.gz | |
-e and -E filter by enabled status
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit_plugins.erl | 23 |
1 files changed, 19 insertions, 4 deletions
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) || |
