summaryrefslogtreecommitdiff
path: root/src/rebar_prv_plugins.erl
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2015-06-19 10:19:12 -0400
committerFred Hebert <mononcqc@ferd.ca>2015-06-19 10:19:12 -0400
commit70dbbf95c24c054514e0ef2ba28c765d33bbf5d7 (patch)
tree8b1bcec2ea3ed1a3adf3a8211d59bab985a4464b /src/rebar_prv_plugins.erl
parent4edfed60a201921995cea987494839eeb6b75638 (diff)
parentf7ff07a87d3e282b4016c1725d149389b0d3b6f9 (diff)
Merge pull request #505 from tsloughter/plugins_provider
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).