← Back to lesson 25: Shape builds and make a command

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.

Original full example
%% 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.

Steps for the full example

  1. Read {profiles, [...]}: Declare profile-specific configuration.
  2. Read {escript_main_app, app}: Choose the application containing main/1.
  3. 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.

Exercise starter
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
Reference 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
Design trade-offs and language comparisons
Original course references