Erlang basics · Lesson 25 (open contents)
Shape builds and make a command
Use Rebar3 profiles for environments and an escript entry point for a small CLI.
Run this first
Run it once, change one input, and compare the new result.
%% cli.erl is the small command boundary
-module(cli).
-export([main/1]).
main(Args) ->
lists:foreach(fun io:format/1, Args).
%% Then run: rebar3 escriptize- Rebar3 creates an executable under
_build/default/bin/when the escript settings are complete.
Read from the first line down
- Read
{profiles, [...]}: Declare profile-specific configuration. - Read
{escript_main_app, app}: Choose the application containingmain/1. - Read
rebar3 escriptize: Build the command under_build.
Symbols are not secret signs
{profiles, [...]}Declare profile-specific configuration.
{escript_main_app, app}Choose the application containing main/1.
rebar3 escriptizeBuild the command under _build.
Match each name to its meaning
profile
A Rebar3 profile changes dependencies or options for a named environment such as test.
dependency
Dependencies belong in rebar.config, where Rebar3 can resolve repeatable versions.
escript
An escript packages BEAM code behind one executable command for a system with Erlang installed.
Why these forms are useful
Run the example first. Predict one result, then change one input and run it again.
A Rebar3 profile changes dependencies or options for a named environment such as test.
Dependencies belong in rebar.config, where Rebar3 can resolve repeatable versions.
Close the answer and try
Print each argument followed by a newline.
lists:foreach(fun(Arg) -> io:format("____", [Arg]) end, Args).Target result: Use the format string ~s~n.
Stuck? Read one hint
~s prints text and ~n ends the line.
After you run it, see one answer
lists:foreach(fun(Arg) -> io:format("~s~n", [Arg]) end, Args).Think about it: Does an escript include a complete Erlang runtime?
No. The target system still needs Erlang installed.
Remember these three lines
- 1
Keep environment options in profiles.
- 2
Let Rebar3 resolve dependencies.
- 3
Keep
main/1thin and move rules into normal modules.