diff options
author | Fred Hebert <mononcqc@ferd.ca> | 2014-11-11 01:27:41 +0000 |
---|---|---|
committer | Fred Hebert <mononcqc@ferd.ca> | 2014-11-11 01:27:41 +0000 |
commit | 392abf148122be020f3955005497d488d3f881fd (patch) | |
tree | c70c4a6b9065b0132e785dcf15b90f9833577c7f | |
parent | 4ed1c4ef581cb780a4b6e2da7cb4e8243b20a370 (diff) |
First unkeyed var is now 'name', appid -> name
The first variable can be unkeyed and the provider will sub in the
variable name 'name'. Additionally, the built-in templates and
documentation have been updated so that 'appid' is now 'name' and the
alternative commands are shown.
-rw-r--r-- | doc/templates.md | 27 | ||||
-rw-r--r-- | priv/templates/README.md.dtl | 2 | ||||
-rw-r--r-- | priv/templates/app.erl.dtl | 6 | ||||
-rw-r--r-- | priv/templates/app.template | 6 | ||||
-rw-r--r-- | priv/templates/lib.template | 6 | ||||
-rw-r--r-- | priv/templates/mod.erl.dtl | 2 | ||||
-rw-r--r-- | priv/templates/otp_app.app.src.dtl | 4 | ||||
-rw-r--r-- | priv/templates/otp_lib.app.src.dtl | 2 | ||||
-rw-r--r-- | priv/templates/plugin.erl.dtl | 4 | ||||
-rw-r--r-- | priv/templates/plugin.template | 6 | ||||
-rw-r--r-- | priv/templates/plugin_README.md.dtl | 10 | ||||
-rw-r--r-- | priv/templates/release.template | 8 | ||||
-rw-r--r-- | priv/templates/relx.config.dtl | 4 | ||||
-rw-r--r-- | priv/templates/sup.erl.dtl | 4 | ||||
-rw-r--r-- | priv/templates/sys.config.dtl | 2 | ||||
-rw-r--r-- | priv/templates/vm.args.dtl | 4 | ||||
-rw-r--r-- | src/rebar_prv_new.erl | 10 |
17 files changed, 62 insertions, 45 deletions
diff --git a/doc/templates.md b/doc/templates.md index 6dd9907..888f356 100644 --- a/doc/templates.md +++ b/doc/templates.md @@ -50,7 +50,7 @@ Details for each individual plugin can be obtained by calling `rebar3 new help < built-in template Description: Rebar3 plugin Variables: - appid="myplugin" (Name of the plugin) + name="myplugin" (Name of the plugin) desc="A rebar plugin" (Short description of the plugin's purpose) date="2014-11-10" datetime="2014-11-10T18:29:41+00:00" @@ -63,6 +63,17 @@ All the variables there have their default values shown, and an optional explana The variables can also be [overriden globally](#global-variables). +A template can be run by calling: + + → ./rebar3 new plugin name=demo author_name="Fred H." + ... + +Alternatively, the `name` variable is special -- if the first argument to a template has no key associated with it, `name` is automatically added. The call above is therefore equivalent to: + + → ./rebar3 new plugin demo author_name="Fred H." + ... + + ## Custom Templates ## Custom templates can be added in `$HOME/.rebar3/templates/`. Each template is at least two files: @@ -107,11 +118,11 @@ We'll start with an index for our template, called `ct_suite.template`: ```erlang {description, "A basic Common Test suite for an OTP application"}. {variables, [ - {suite, "suite", "Name of the suite, prepended to the standard _SUITE suffix"} + {name, "suite", "Name of the suite, prepended to the standard _SUITE suffix"} ]}. {dir, "test"}. -{template, "ct_suite.erl.dtl", "test/{{suite}}_SUITE.erl"}. +{template, "ct_suite.erl.dtl", "test/{{name}}_SUITE.erl"}. ``` This tells rebar3 to create the test directory and to evaluate an [ErlyDTL](https://github.com/erlydtl/erlydtl) template. All the paths are relative to the current working directory. @@ -119,7 +130,7 @@ This tells rebar3 to create the test directory and to evaluate an [ErlyDTL](http Let's create the template file: ```erlang --module({{suite}}_SUITE). +-module({{name}}_SUITE). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). % Eunit macros for convenience @@ -145,7 +156,7 @@ fail(_Config) -> ?assert(false). ``` -This one does very simple variable substitution for the name (using `{{suite}}`) and that's all it needs. +This one does very simple variable substitution for the name (using `{{name}}`) and that's all it needs. Let's get to any existing project you have and try it: @@ -164,7 +175,7 @@ Let's look at the details: custom template (/home/ferd/.rebar3/templates/ct_suite.template) Description: A basic Common Test suite for an OTP application Variables: - suite="suite" (Name of the suite, prepended to the standard _SUITE suffix) + name="suite" (Name of the suite, prepended to the standard _SUITE suffix) date="2014-11-10" datetime="2014-11-10T18:46:33+00:00" author_name="Anonymous" @@ -174,9 +185,7 @@ Let's look at the details: The documentation from variables and the description are well in place. To apply the template, go to any of your OTP application's top-level directory: - → ./rebar3 new ct_suite suite=demo + → ./rebar3 new ct_suite demo ===> Writing test/demo_SUITE.erl And you will see the code in place. - -~ diff --git a/priv/templates/README.md.dtl b/priv/templates/README.md.dtl index 900fedb..5507536 100644 --- a/priv/templates/README.md.dtl +++ b/priv/templates/README.md.dtl @@ -1,4 +1,4 @@ -{{appid}} +{{name}} ===== {{desc}} diff --git a/priv/templates/app.erl.dtl b/priv/templates/app.erl.dtl index 1c3e8f2..83eb9a3 100644 --- a/priv/templates/app.erl.dtl +++ b/priv/templates/app.erl.dtl @@ -1,9 +1,9 @@ %%%------------------------------------------------------------------- -%% @doc {{appid}} public API +%% @doc {{name}} public API %% @end %%%------------------------------------------------------------------- --module({{appid}}_app). +-module({{name}}_app). -behaviour(application). @@ -16,7 +16,7 @@ %%==================================================================== start(_StartType, _StartArgs) -> - {{appid}}_sup:start_link(). + {{name}}_sup:start_link(). %%-------------------------------------------------------------------- stop(_State) -> diff --git a/priv/templates/app.template b/priv/templates/app.template index 39ec14a..78374af 100644 --- a/priv/templates/app.template +++ b/priv/templates/app.template @@ -1,10 +1,10 @@ {description, "OTP Application"}. {variables, [ - {appid, "mylib", "Name of the OTP application"}, + {name, "mylib", "Name of the OTP application"}, {desc, "An OTP application", "Short description of the app"} ]}. -{template, "app.erl.dtl", "src/{{appid}}_app.erl"}. -{template, "otp_app.app.src.dtl", "src/{{appid}}.app.src"}. +{template, "app.erl.dtl", "src/{{name}}_app.erl"}. +{template, "otp_app.app.src.dtl", "src/{{name}}.app.src"}. {template, "rebar.config.dtl", "rebar.config"}. {template, "gitignore.dtl", ".gitignore"}. {template, "LICENSE.dtl", "LICENSE"}. diff --git a/priv/templates/lib.template b/priv/templates/lib.template index 3f35945..1db3b07 100644 --- a/priv/templates/lib.template +++ b/priv/templates/lib.template @@ -1,10 +1,10 @@ {description, "OTP Library application (no processes)"}. {variables, [ - {appid, "mylib", "Name of the OTP library application"}, + {name, "mylib", "Name of the OTP library application"}, {desc, "An OTP library", "Short description of the app"} ]}. -{template, "mod.erl.dtl", "src/{{appid}}.erl"}. -{template, "otp_lib.app.src.dtl", "src/{{appid}}.app.src"}. +{template, "mod.erl.dtl", "src/{{name}}.erl"}. +{template, "otp_lib.app.src.dtl", "src/{{name}}.app.src"}. {template, "rebar.config.dtl", "rebar.config"}. {template, "gitignore.dtl", ".gitignore"}. {template, "LICENSE.dtl", "LICENSE"}. diff --git a/priv/templates/mod.erl.dtl b/priv/templates/mod.erl.dtl index 2453366..2f5e09e 100644 --- a/priv/templates/mod.erl.dtl +++ b/priv/templates/mod.erl.dtl @@ -1,4 +1,4 @@ --module({{appid}}). +-module({{name}}). %% API exports -export([]). diff --git a/priv/templates/otp_app.app.src.dtl b/priv/templates/otp_app.app.src.dtl index cd5ac89..5188f56 100644 --- a/priv/templates/otp_app.app.src.dtl +++ b/priv/templates/otp_app.app.src.dtl @@ -1,8 +1,8 @@ -{application, {{appid}}, +{application, {{name}}, [{description, "{{desc}}"} ,{vsn, "0.1.0"} ,{registered, []} - ,{mod, {'{{appid}}_app', []}} + ,{mod, {'{{name}}_app', []}} ,{applications, [kernel ,stdlib diff --git a/priv/templates/otp_lib.app.src.dtl b/priv/templates/otp_lib.app.src.dtl index 53ebbb0..3adefeb 100644 --- a/priv/templates/otp_lib.app.src.dtl +++ b/priv/templates/otp_lib.app.src.dtl @@ -1,4 +1,4 @@ -{application, {{appid}}, +{application, {{name}}, [{description, "{{desc}}"} ,{vsn, "0.1.0"} ,{registered, []} diff --git a/priv/templates/plugin.erl.dtl b/priv/templates/plugin.erl.dtl index e51763b..df92cf6 100644 --- a/priv/templates/plugin.erl.dtl +++ b/priv/templates/plugin.erl.dtl @@ -1,4 +1,4 @@ --module({{appid}}). +-module({{name}}). -behaviour(provider). -export([init/1, do/1, format_error/2]). @@ -18,7 +18,7 @@ init(State) -> {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, "rebar {{appid}}"}, % How to use the plugin + {example, "rebar {{name}}"}, % How to use the plugin {opts, []} % list of options understood by the plugin {short_desc, {{desc}}}, {desc, ""} diff --git a/priv/templates/plugin.template b/priv/templates/plugin.template index 7235b60..a7e15cc 100644 --- a/priv/templates/plugin.template +++ b/priv/templates/plugin.template @@ -1,10 +1,10 @@ {description, "Rebar3 plugin"}. {variables, [ - {appid, "myplugin", "Name of the plugin"}, + {name, "myplugin", "Name of the plugin"}, {desc, "A rebar plugin", "Short description of the plugin's purpose"} ]}. -{template, "plugin.erl.dtl", "src/{{appid}}.erl"}. -{template, "otp_lib.app.src.dtl", "src/{{appid}}.app.src"}. +{template, "plugin.erl.dtl", "src/{{name}}.erl"}. +{template, "otp_lib.app.src.dtl", "src/{{name}}.app.src"}. {template, "rebar.config.dtl", "rebar.config"}. {template, "gitignore.dtl", ".gitignore"}. {template, "LICENSE.dtl", "LICENSE"}. diff --git a/priv/templates/plugin_README.md.dtl b/priv/templates/plugin_README.md.dtl index c784324..8c91947 100644 --- a/priv/templates/plugin_README.md.dtl +++ b/priv/templates/plugin_README.md.dtl @@ -1,4 +1,4 @@ -{{appid}} +{{name}} ===== {{desc}} @@ -14,14 +14,14 @@ Use Add the plugin to your rebar config: {plugins, [ - { {{appid}}, ".*", {git, "git@host:user/{{appid}}.git", {tag, "0.1.0"}}} + { {{name}}, ".*", {git, "git@host:user/{{name}}.git", {tag, "0.1.0"}}} ]}. Then just call your plugin directly in an existing application: - $ rebar3 {{appid}} - ===> Fetching {{appid}} + $ rebar3 {{name}} + ===> Fetching {{name}} Cloning into '.tmp_dir539136867963'... - ===> Compiling {{appid}} + ===> Compiling {{name}} <Plugin Output> diff --git a/priv/templates/release.template b/priv/templates/release.template index 5e3ba1a..3539392 100644 --- a/priv/templates/release.template +++ b/priv/templates/release.template @@ -1,11 +1,11 @@ {description, "OTP Release structure for executable programs"}. {variables, [ - {appid, "myapp", "Name of the OTP release. An app with this name will also be created."}, + {name, "myapp", "Name of the OTP release. An app with this name will also be created."}, {desc, "An OTP application", "Short description of the release's main app's purpose"} ]}. -{template, "app.erl.dtl", "{{apps_dir}}/{{appid}}/src/{{appid}}_app.erl"}. -{template, "sup.erl.dtl", "{{apps_dir}}/{{appid}}/src/{{appid}}_sup.erl"}. -{template, "otp_app.app.src.dtl", "{{apps_dir}}/{{appid}}/src/{{appid}}.app.src"}. +{template, "app.erl.dtl", "{{apps_dir}}/{{name}}/src/{{name}}_app.erl"}. +{template, "sup.erl.dtl", "{{apps_dir}}/{{name}}/src/{{name}}_sup.erl"}. +{template, "otp_app.app.src.dtl", "{{apps_dir}}/{{name}}/src/{{name}}.app.src"}. {template, "rebar.config.dtl", "rebar.config"}. {template, "relx.config.dtl", "relx.config"}. {template, "sys.config.dtl", "config/sys.config"}. diff --git a/priv/templates/relx.config.dtl b/priv/templates/relx.config.dtl index 7cb3a8a..7b08f97 100644 --- a/priv/templates/relx.config.dtl +++ b/priv/templates/relx.config.dtl @@ -1,6 +1,6 @@ %% -*- mode: Erlang; fill-column: 80; comment-column: 75; -*- -{release, {'{{appid}}', "0.1.0"}, - [{{appid}}, +{release, {'{{name}}', "0.1.0"}, + [{{name}}, sasl]}. {sys_config, "./config/sys.config"}. diff --git a/priv/templates/sup.erl.dtl b/priv/templates/sup.erl.dtl index 3dd5b12..a2e7209 100644 --- a/priv/templates/sup.erl.dtl +++ b/priv/templates/sup.erl.dtl @@ -1,9 +1,9 @@ %%%------------------------------------------------------------------- -%% @doc {{appid}} top level supervisor. +%% @doc {{name}} top level supervisor. %% @end %%%------------------------------------------------------------------- --module({{appid}}_sup). +-module({{name}}_sup). -behaviour(supervisor). diff --git a/priv/templates/sys.config.dtl b/priv/templates/sys.config.dtl index e678cf7..7fd6bcb 100644 --- a/priv/templates/sys.config.dtl +++ b/priv/templates/sys.config.dtl @@ -1,3 +1,3 @@ [ - {'{{appid}}', []} + {'{{name}}', []} ]. diff --git a/priv/templates/vm.args.dtl b/priv/templates/vm.args.dtl index 27028ac..a8a43f0 100644 --- a/priv/templates/vm.args.dtl +++ b/priv/templates/vm.args.dtl @@ -1,6 +1,6 @@ --name {{appid}} +-name {{name}} --setcookie {{appid}}_cookie +-setcookie {{name}}_cookie +K true +A30 diff --git a/src/rebar_prv_new.erl b/src/rebar_prv_new.erl index 93adeb4..e432371 100644 --- a/src/rebar_prv_new.erl +++ b/src/rebar_prv_new.erl @@ -71,7 +71,15 @@ is_forced(State) -> end. parse_opts([]) -> []; -parse_opts([Opt|Opts]) -> [parse_opt(Opt, "") | parse_opts(Opts)]. +parse_opts([Opt|Opts]) -> [parse_first_opt(Opt, "") | parse_opts1(Opts)]. + +parse_opts1([]) -> []; +parse_opts1([Opt|Opts]) -> [parse_opt(Opt, "") | parse_opts1(Opts)]. + +%% If the first argument meets no '=', we got a default 'name' argument +parse_first_opt("", Acc) -> {name, lists:reverse(Acc)}; +parse_first_opt("="++Rest, Acc) -> parse_opt("="++Rest, Acc); +parse_first_opt([H|Str], Acc) -> parse_first_opt(Str, [H|Acc]). %% We convert to atoms dynamically. Horrible in general, but fine in a %% build system's templating tool. |