Helper to generate a script that takes command-line arguments
Bakeware supports an API similar to Escript for implementing a main
function.
The main
function will take 2 arguments:
arg0
- The absolute path to the executableargs
- Analogous to argv in other languages. A list or arguments passed to the executable
The main
function must return a superset of functions that :erlang.halt/1 supports:
- integer -> returning an integer will set the exit status. IE success: 0, error: >= 1
- iodata -> An Erlang crash dump is produced with
iodata
as slogan. Then the runtime system exits with status code 1. The string will be truncated if longer than 200 characters. - :abort -> The runtime system aborts producing a core dump, if that is enabled in the OS.
Example:
defmodule MyApp.Main do
use Bakeware.Script
@impl Bakeware.Script
def main(_arg0, _args) do
IO.puts "Hello, World!"
0
end
end
Specs
args() :: [String.t()]
Specs
main(args()) :: :ok | :error | non_neg_integer() | :abort | charlist() | String.t()