summaryrefslogtreecommitdiff
path: root/src/rebar_prv_new.erl
diff options
context:
space:
mode:
authorHeinz N. Gies <heinz@licenser.net>2016-02-08 11:15:59 -0500
committerHeinz N. Gies <heinz@licenser.net>2016-02-08 11:15:59 -0500
commit2f563041cb248ba0cac27b92da5dcc3e7be27f80 (patch)
treee27ecaf59cfeb0e6406f1f4ce753842ff52855d5 /src/rebar_prv_new.erl
parent91c47db27a3c63fc04940c7c72433062dbadf042 (diff)
parent7fab47dfa05754242790a748bbd303ffe9703e5c (diff)
Merge master
Diffstat (limited to 'src/rebar_prv_new.erl')
-rw-r--r--src/rebar_prv_new.erl29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/rebar_prv_new.erl b/src/rebar_prv_new.erl
index 6574aca..064315e 100644
--- a/src/rebar_prv_new.erl
+++ b/src/rebar_prv_new.erl
@@ -7,6 +7,7 @@
format_error/1]).
-include("rebar.hrl").
+-include_lib("providers/include/providers.hrl").
-define(PROVIDER, new).
-define(DEPS, []).
@@ -32,19 +33,19 @@ init(State) ->
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
- case rebar_state:command_args(State) of
+ case strip_flags(rebar_state:command_args(State)) of
["help"] ->
?CONSOLE("Call `rebar3 new help <template>` for a detailed description~n", []),
- show_short_templates(rebar_templater:list_templates(State)),
+ show_short_templates(list_templates(State)),
{ok, State};
["help", TemplateName] ->
- case lists:keyfind(TemplateName, 1, rebar_templater:list_templates(State)) of
+ case lists:keyfind(TemplateName, 1, list_templates(State)) of
false -> ?CONSOLE("template not found.", []);
Term -> show_template(Term)
end,
{ok, State};
[TemplateName | Opts] ->
- case lists:keyfind(TemplateName, 1, rebar_templater:list_templates(State)) of
+ case lists:keyfind(TemplateName, 1, list_templates(State)) of
false ->
?CONSOLE("template not found.", []);
_ ->
@@ -53,11 +54,13 @@ do(State) ->
end,
{ok, State};
[] ->
- show_short_templates(rebar_templater:list_templates(State)),
+ show_short_templates(list_templates(State)),
{ok, State}
end.
-spec format_error(any()) -> iolist().
+format_error({consult, File, Reason}) ->
+ io_lib:format("Error consulting file at ~s for reason ~p", [File, Reason]);
format_error(Reason) ->
io_lib:format("~p", [Reason]).
@@ -65,6 +68,15 @@ format_error(Reason) ->
%% Internal functions
%% ===================================================================
+list_templates(State) ->
+ lists:foldl(fun({error, {consult, File, Reason}}, Acc) ->
+ ?WARN("Error consulting template file ~s for reason ~p",
+ [File, Reason]),
+ Acc
+ ; (Tpl, Acc) ->
+ [Tpl|Acc]
+ end, [], lists:reverse(rebar_templater:list_templates(State))).
+
info() ->
io_lib:format(
"Create rebar3 project based on template and vars.~n"
@@ -72,6 +84,10 @@ info() ->
"Valid command line options:~n"
" <template> [var=foo,...]~n", []).
+strip_flags([]) -> [];
+strip_flags(["-"++_|Opts]) -> strip_flags(Opts);
+strip_flags([Opt | Opts]) -> [Opt | strip_flags(Opts)].
+
is_forced(State) ->
{Args, _} = rebar_state:command_parsed_args(State),
case proplists:get_value(force, Args) of
@@ -116,10 +132,13 @@ show_template({Name, Type, Location, Description, Vars}) ->
format_vars(Vars)]).
format_type(escript) -> "built-in";
+format_type(plugin) -> "plugin";
format_type(file) -> "custom".
format_type(escript, _) ->
"built-in template";
+format_type(plugin, Loc) ->
+ io_lib:format("plugin template (~s)", [Loc]);
format_type(file, Loc) ->
io_lib:format("custom template (~s)", [Loc]).