summaryrefslogtreecommitdiff
path: root/src/rebar_prv_plugins.erl
diff options
context:
space:
mode:
authorTristan Sloughter <t@crashfast.com>2015-06-03 23:09:43 -0500
committerTristan Sloughter <t@crashfast.com>2015-06-18 22:08:19 -0500
commitf7ff07a87d3e282b4016c1725d149389b0d3b6f9 (patch)
tree8b1bcec2ea3ed1a3adf3a8211d59bab985a4464b /src/rebar_prv_plugins.erl
parent4edfed60a201921995cea987494839eeb6b75638 (diff)
plugins provider
Diffstat (limited to 'src/rebar_prv_plugins.erl')
-rw-r--r--src/rebar_prv_plugins.erl67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/rebar_prv_plugins.erl b/src/rebar_prv_plugins.erl
new file mode 100644
index 0000000..328958e
--- /dev/null
+++ b/src/rebar_prv_plugins.erl
@@ -0,0 +1,67 @@
+-module(rebar_prv_plugins).
+
+-behaviour(provider).
+
+-export([init/1,
+ do/1,
+ format_error/1]).
+
+-include("rebar.hrl").
+-include_lib("providers/include/providers.hrl").
+
+-define(PROVIDER, list).
+-define(NAMESPACE, plugins).
+-define(DEPS, []).
+
+-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
+init(State) ->
+ State1 = rebar_state:add_provider(
+ State,
+ providers:create([
+ {name, ?PROVIDER},
+ {module, ?MODULE},
+ {namespace, ?NAMESPACE},
+ {bare, true},
+ {deps, ?DEPS},
+ {example, "rebar3 plugins list"},
+ {short_desc, "List local and global plugins for this project"},
+ {desc, "List local and global plugins for this project"},
+ {opts, []}])),
+ {ok, State1}.
+
+-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
+do(State) ->
+ GlobalConfigFile = rebar_dir:global_config(),
+ GlobalConfig = rebar_state:new(rebar_config:consult_file(GlobalConfigFile)),
+ GlobalPlugins = rebar_state:get(GlobalConfig, plugins, []),
+ GlobalPluginsDir = filename:join(rebar_dir:global_cache_dir(State), "plugins"),
+ display_plugins("Global plugins", GlobalPluginsDir, GlobalPlugins),
+
+ Plugins = rebar_state:get(State, plugins, []),
+ PluginsDir =rebar_dir:plugins_dir(State),
+ display_plugins("Local plugins", PluginsDir, Plugins),
+ {ok, State}.
+
+-spec format_error(any()) -> iolist().
+format_error(Reason) ->
+ io_lib:format("~p", [Reason]).
+
+display_plugins(_Header, _Dir, []) ->
+ ok;
+display_plugins(Header, Dir, Plugins) ->
+ ?CONSOLE("--- ~s ---", [Header]),
+ display_plugins(Dir, Plugins),
+ ?CONSOLE("", []).
+
+display_plugins(Dir, Plugins) ->
+ lists:foreach(fun(Plugin) ->
+ Name = if is_atom(Plugin) -> Plugin;
+ is_tuple(Plugin) -> element(1, Plugin)
+ end,
+ case rebar_app_info:discover(filename:join(Dir, Name)) of
+ {ok, _App} ->
+ ?CONSOLE("~s", [Name]);
+ not_found ->
+ ?DEBUG("Unable to find plugin ~s", [Name])
+ end
+ end, Plugins).