From f72b39f3c399a1fcf2b039358d20c045b3741915 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sat, 23 Aug 2014 14:48:05 -0500 Subject: allow new project dir for template --- src/rebar_prv_new.erl | 6 +++++- src/rebar_templater.erl | 20 +++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/rebar_prv_new.erl b/src/rebar_prv_new.erl index e5233cd..528c95e 100644 --- a/src/rebar_prv_new.erl +++ b/src/rebar_prv_new.erl @@ -31,7 +31,11 @@ do(State) -> case rebar_state:command_args(State) of [TemplateName] -> Template = list_to_atom(TemplateName), - rebar_templater:new(Template, State), + rebar_templater:new(Template, "", State), + {ok, State}; + [TemplateName, DirName] -> + Template = list_to_atom(TemplateName), + rebar_templater:new(Template, DirName, State), {ok, State}; [] -> {ok, State} diff --git a/src/rebar_templater.erl b/src/rebar_templater.erl index f22329b..820bd0c 100644 --- a/src/rebar_templater.erl +++ b/src/rebar_templater.erl @@ -26,7 +26,7 @@ %% ------------------------------------------------------------------- -module(rebar_templater). --export([new/2, +-export([new/3, list_templates/1, create/1]). @@ -42,13 +42,13 @@ %% Public API %% =================================================================== -new(app, Config) -> - create1(Config, "simpleapp"); -new(lib, Config) -> - create1(Config, "simplelib"); -new(node, Config) -> +new(app, DirName, Config) -> + create1(Config, DirName, "simpleapp"); +new(lib, DirName, Config) -> + create1(Config, DirName, "simplelib"); +new(node, DirName, Config) -> %% Alias for create w/ template=simplenode - create1(Config, "simplenode"). + create1(Config, DirName, "simplenode"). list_templates(Config) -> {AvailTemplates, Files} = find_templates(Config), @@ -69,7 +69,7 @@ list_templates(Config) -> create(Config) -> TemplateId = template_id(Config), - create1(Config, TemplateId). + create1(Config, "", TemplateId). %% %% Given a list of key value pairs, for each string value attempt to @@ -100,7 +100,9 @@ render(Bin, Context) -> %% Internal functions %% =================================================================== -create1(Config, TemplateId) -> +create1(Config, AppDir, TemplateId) -> + ec_file:mkdir_p(AppDir), + file:set_cwd(AppDir), {AvailTemplates, Files} = find_templates(Config), ?DEBUG("Available templates: ~p\n", [AvailTemplates]), -- cgit v1.1