Browse Source

update plugin template to separate plugin init and providers

pull/573/head
Tristan Sloughter 9 years ago
parent
commit
ac0a8d40cd
3 changed files with 36 additions and 28 deletions
  1. +3
    -28
      priv/templates/plugin.erl
  2. +1
    -0
      priv/templates/plugin.template
  3. +32
    -0
      priv/templates/provider.erl

+ 3
- 28
priv/templates/plugin.erl View File

@ -1,33 +1,8 @@
-module('{{name}}').
-behaviour(provider).
-export([init/1, do/1, format_error/1]).
-export([init/1]).
-define(PROVIDER, '{{name}}').
-define(DEPS, [app_discovery]).
%% ===================================================================
%% Public API
%% ===================================================================
-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
Provider = providers:create([
{name, ?PROVIDER}, % The 'user friendly' name of the task
{module, ?MODULE}, % The module implementation of the task
{bare, true}, % The task can be run by the user, always true
{deps, ?DEPS}, % The list of dependencies
{example, "rebar3 {{name}}"}, % How to use the plugin
{opts, []}, % list of options understood by the plugin
{short_desc, "{{desc}}"},
{desc, "{{desc}}"}
]),
{ok, rebar_state:add_provider(State, Provider)}.
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
{ok, State}.
-spec format_error(any()) -> iolist().
format_error(Reason) ->
io_lib:format("~p", [Reason]).
{ok, State1} = '{{name}}_prv':init(State),
{ok, State1}.

+ 1
- 0
priv/templates/plugin.template View File

@ -4,6 +4,7 @@
{desc, "A rebar plugin", "Short description of the plugin's purpose"}
]}.
{template, "plugin.erl", "{{name}}/src/{{name}}.erl"}.
{template, "provider.erl", "{{name}}/src/prv_{{name}}_prv.erl"}.
{template, "otp_lib.app.src", "{{name}}/src/{{name}}.app.src"}.
{template, "rebar.config", "{{name}}/rebar.config"}.
{template, "gitignore", "{{name}}/.gitignore"}.

+ 32
- 0
priv/templates/provider.erl View File

@ -0,0 +1,32 @@
-module('{{name}}_prv').
-export([init/1, do/1, format_error/1]).
-define(PROVIDER, '{{name}}').
-define(DEPS, [app_discovery]).
%% ===================================================================
%% Public API
%% ===================================================================
-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
Provider = providers:create([
{name, ?PROVIDER}, % The 'user friendly' name of the task
{module, ?MODULE}, % The module implementation of the task
{bare, true}, % The task can be run by the user, always true
{deps, ?DEPS}, % The list of dependencies
{example, "rebar3 {{name}}"}, % How to use the plugin
{opts, []}, % list of options understood by the plugin
{short_desc, "{{desc}}"},
{desc, "{{desc}}"}
]),
{ok, rebar_state:add_provider(State, Provider)}.
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
{ok, State}.
-spec format_error(any()) -> iolist().
format_error(Reason) ->
io_lib:format("~p", [Reason]).

Loading…
Cancel
Save