Bakeware.Script behaviour (bakeware v0.1.2)

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 executable
  • args - 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

Types

args()

Specs

args() :: [String.t()]

Functions

__using__(opts)

(macro)

Defines an app spec that will execute a script

get_argc!()

(macro)

get_args(argc)

(macro)

result_to_halt(result)

(macro)

Callbacks

main(args)

Specs

main(args()) ::
  :ok | :error | non_neg_integer() | :abort | charlist() | String.t()