Browse Source

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.
pull/3/head
Fred Hebert 10 years ago
parent
commit
392abf1481
17 changed files with 62 additions and 45 deletions
  1. +18
    -9
      doc/templates.md
  2. +1
    -1
      priv/templates/README.md.dtl
  3. +3
    -3
      priv/templates/app.erl.dtl
  4. +3
    -3
      priv/templates/app.template
  5. +3
    -3
      priv/templates/lib.template
  6. +1
    -1
      priv/templates/mod.erl.dtl
  7. +2
    -2
      priv/templates/otp_app.app.src.dtl
  8. +1
    -1
      priv/templates/otp_lib.app.src.dtl
  9. +2
    -2
      priv/templates/plugin.erl.dtl
  10. +3
    -3
      priv/templates/plugin.template
  11. +5
    -5
      priv/templates/plugin_README.md.dtl
  12. +4
    -4
      priv/templates/release.template
  13. +2
    -2
      priv/templates/relx.config.dtl
  14. +2
    -2
      priv/templates/sup.erl.dtl
  15. +1
    -1
      priv/templates/sys.config.dtl
  16. +2
    -2
      priv/templates/vm.args.dtl
  17. +9
    -1
      src/rebar_prv_new.erl

+ 18
- 9
doc/templates.md View File

@ -50,7 +50,7 @@ Details for each individual plugin can be obtained by calling `rebar3 new help <
built-in template built-in template
Description: Rebar3 plugin Description: Rebar3 plugin
Variables: Variables:
appid="myplugin" (Name of the plugin)
name="myplugin" (Name of the plugin)
desc="A rebar plugin" (Short description of the plugin's purpose) desc="A rebar plugin" (Short description of the plugin's purpose)
date="2014-11-10" date="2014-11-10"
datetime="2014-11-10T18:29:41+00:00" 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). 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 ##
Custom templates can be added in `$HOME/.rebar3/templates/`. Each template is at least two files: 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 ```erlang
{description, "A basic Common Test suite for an OTP application"}. {description, "A basic Common Test suite for an OTP application"}.
{variables, [ {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"}. {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. 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: Let's create the template file:
```erlang ```erlang
-module({{suite}}_SUITE).
-module({{name}}_SUITE).
-include_lib("common_test/include/ct.hrl"). -include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl"). % Eunit macros for convenience -include_lib("eunit/include/eunit.hrl"). % Eunit macros for convenience
@ -145,7 +156,7 @@ fail(_Config) ->
?assert(false). ?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: 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) custom template (/home/ferd/.rebar3/templates/ct_suite.template)
Description: A basic Common Test suite for an OTP application Description: A basic Common Test suite for an OTP application
Variables: 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" date="2014-11-10"
datetime="2014-11-10T18:46:33+00:00" datetime="2014-11-10T18:46:33+00:00"
author_name="Anonymous" 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: 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 ===> Writing test/demo_SUITE.erl
And you will see the code in place. And you will see the code in place.
~

+ 1
- 1
priv/templates/README.md.dtl View File

@ -1,4 +1,4 @@
{{appid}}
{{name}}
===== =====
{{desc}} {{desc}}

+ 3
- 3
priv/templates/app.erl.dtl View File

@ -1,9 +1,9 @@
%%%------------------------------------------------------------------- %%%-------------------------------------------------------------------
%% @doc {{appid}} public API
%% @doc {{name}} public API
%% @end %% @end
%%%------------------------------------------------------------------- %%%-------------------------------------------------------------------
-module({{appid}}_app).
-module({{name}}_app).
-behaviour(application). -behaviour(application).
@ -16,7 +16,7 @@
%%==================================================================== %%====================================================================
start(_StartType, _StartArgs) -> start(_StartType, _StartArgs) ->
{{appid}}_sup:start_link().
{{name}}_sup:start_link().
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
stop(_State) -> stop(_State) ->

+ 3
- 3
priv/templates/app.template View File

@ -1,10 +1,10 @@
{description, "OTP Application"}. {description, "OTP Application"}.
{variables, [ {variables, [
{appid, "mylib", "Name of the OTP application"},
{name, "mylib", "Name of the OTP application"},
{desc, "An OTP application", "Short description of the app"} {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, "rebar.config.dtl", "rebar.config"}.
{template, "gitignore.dtl", ".gitignore"}. {template, "gitignore.dtl", ".gitignore"}.
{template, "LICENSE.dtl", "LICENSE"}. {template, "LICENSE.dtl", "LICENSE"}.

+ 3
- 3
priv/templates/lib.template View File

@ -1,10 +1,10 @@
{description, "OTP Library application (no processes)"}. {description, "OTP Library application (no processes)"}.
{variables, [ {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"} {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, "rebar.config.dtl", "rebar.config"}.
{template, "gitignore.dtl", ".gitignore"}. {template, "gitignore.dtl", ".gitignore"}.
{template, "LICENSE.dtl", "LICENSE"}. {template, "LICENSE.dtl", "LICENSE"}.

+ 1
- 1
priv/templates/mod.erl.dtl View File

@ -1,4 +1,4 @@
-module({{appid}}).
-module({{name}}).
%% API exports %% API exports
-export([]). -export([]).

+ 2
- 2
priv/templates/otp_app.app.src.dtl View File

@ -1,8 +1,8 @@
{application, {{appid}},
{application, {{name}},
[{description, "{{desc}}"} [{description, "{{desc}}"}
,{vsn, "0.1.0"} ,{vsn, "0.1.0"}
,{registered, []} ,{registered, []}
,{mod, {'{{appid}}_app', []}}
,{mod, {'{{name}}_app', []}}
,{applications, ,{applications,
[kernel [kernel
,stdlib ,stdlib

+ 1
- 1
priv/templates/otp_lib.app.src.dtl View File

@ -1,4 +1,4 @@
{application, {{appid}},
{application, {{name}},
[{description, "{{desc}}"} [{description, "{{desc}}"}
,{vsn, "0.1.0"} ,{vsn, "0.1.0"}
,{registered, []} ,{registered, []}

+ 2
- 2
priv/templates/plugin.erl.dtl View File

@ -1,4 +1,4 @@
-module({{appid}}).
-module({{name}}).
-behaviour(provider). -behaviour(provider).
-export([init/1, do/1, format_error/2]). -export([init/1, do/1, format_error/2]).
@ -18,7 +18,7 @@ init(State) ->
{module, ?MODULE}, % The module implementation of the task {module, ?MODULE}, % The module implementation of the task
{bare, true}, % The task can be run by the user, always true {bare, true}, % The task can be run by the user, always true
{deps, ?DEPS}, % The list of dependencies {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 {opts, []} % list of options understood by the plugin
{short_desc, {{desc}}}, {short_desc, {{desc}}},
{desc, ""} {desc, ""}

+ 3
- 3
priv/templates/plugin.template View File

@ -1,10 +1,10 @@
{description, "Rebar3 plugin"}. {description, "Rebar3 plugin"}.
{variables, [ {variables, [
{appid, "myplugin", "Name of the plugin"},
{name, "myplugin", "Name of the plugin"},
{desc, "A rebar plugin", "Short description of the plugin's purpose"} {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, "rebar.config.dtl", "rebar.config"}.
{template, "gitignore.dtl", ".gitignore"}. {template, "gitignore.dtl", ".gitignore"}.
{template, "LICENSE.dtl", "LICENSE"}. {template, "LICENSE.dtl", "LICENSE"}.

+ 5
- 5
priv/templates/plugin_README.md.dtl View File

@ -1,4 +1,4 @@
{{appid}}
{{name}}
===== =====
{{desc}} {{desc}}
@ -14,14 +14,14 @@ Use
Add the plugin to your rebar config: Add the plugin to your rebar config:
{plugins, [ {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: Then just call your plugin directly in an existing application:
$ rebar3 {{appid}}
===> Fetching {{appid}}
$ rebar3 {{name}}
===> Fetching {{name}}
Cloning into '.tmp_dir539136867963'... Cloning into '.tmp_dir539136867963'...
===> Compiling {{appid}}
===> Compiling {{name}}
<Plugin Output> <Plugin Output>

+ 4
- 4
priv/templates/release.template View File

@ -1,11 +1,11 @@
{description, "OTP Release structure for executable programs"}. {description, "OTP Release structure for executable programs"}.
{variables, [ {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"} {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, "rebar.config.dtl", "rebar.config"}.
{template, "relx.config.dtl", "relx.config"}. {template, "relx.config.dtl", "relx.config"}.
{template, "sys.config.dtl", "config/sys.config"}. {template, "sys.config.dtl", "config/sys.config"}.

+ 2
- 2
priv/templates/relx.config.dtl View File

@ -1,6 +1,6 @@
%% -*- mode: Erlang; fill-column: 80; comment-column: 75; -*- %% -*- mode: Erlang; fill-column: 80; comment-column: 75; -*-
{release, {'{{appid}}', "0.1.0"},
[{{appid}},
{release, {'{{name}}', "0.1.0"},
[{{name}},
sasl]}. sasl]}.
{sys_config, "./config/sys.config"}. {sys_config, "./config/sys.config"}.

+ 2
- 2
priv/templates/sup.erl.dtl View File

@ -1,9 +1,9 @@
%%%------------------------------------------------------------------- %%%-------------------------------------------------------------------
%% @doc {{appid}} top level supervisor.
%% @doc {{name}} top level supervisor.
%% @end %% @end
%%%------------------------------------------------------------------- %%%-------------------------------------------------------------------
-module({{appid}}_sup).
-module({{name}}_sup).
-behaviour(supervisor). -behaviour(supervisor).

+ 1
- 1
priv/templates/sys.config.dtl View File

@ -1,3 +1,3 @@
[ [
{'{{appid}}', []}
{'{{name}}', []}
]. ].

+ 2
- 2
priv/templates/vm.args.dtl View File

@ -1,6 +1,6 @@
-name {{appid}}
-name {{name}}
-setcookie {{appid}}_cookie
-setcookie {{name}}_cookie
+K true +K true
+A30 +A30

+ 9
- 1
src/rebar_prv_new.erl View File

@ -71,7 +71,15 @@ is_forced(State) ->
end. end.
parse_opts([]) -> []; 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 %% We convert to atoms dynamically. Horrible in general, but fine in a
%% build system's templating tool. %% build system's templating tool.

Loading…
Cancel
Save