Shape builds and make a command: full examples and further reading
The original lesson material is preserved here for reference. The main notebook focuses on this lesson's core question.
Use Rebar3 profiles for environments and an escript entry point for a small CLI.
Build an escript whose main/1 receives command-line arguments.
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 escriptizeRebar3 creates an executable under _build/default/bin/ when the escript settings are complete.
Steps for the full example
- Read
{profiles, [...]}: Declare profile-specific configuration. - Read
{escript_main_app, app}: Choose the application containingmain/1. - Read
rebar3 escriptize: Build the command under_build.
Original lesson notes
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.
Symbols and terms
{profiles, [...]}- Declare profile-specific configuration.
{escript_main_app, app}- Choose the application containing
main/1. rebar3 escriptize- Build the command under
_build. - 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.
Original full exercise
Print each argument followed by a newline.
lists:foreach(fun(Arg) -> io:format("____", [Arg]) end, Args).Use the format string ~s~n.
Show hint
~s prints text and ~n ends the line.
Show original answer
lists:foreach(fun(Arg) -> io:format("~s~n", [Arg]) end, Args).Does an escript include a complete Erlang runtime?
No. The target system still needs Erlang installed.
Original lesson takeaways
- Keep environment options in profiles.
- Let Rebar3 resolve dependencies.
- Keep
main/1thin and move rules into normal modules.