Bakeware.Script behaviour (bakeware v0.1.5) View Source

Helper to generate a script that takes command-line arguments

Bakeware supports an API similar to Erlang's escript for implementing a main function. Here's an example module:

defmodule MyApp.Main do
  use Bakeware.Script

  @impl Bakeware.Script
  def main(_args) do
    IO.puts "Hello, World!"
    0
  end
end

The return value sets the scripts exit status (0 for success and other values for errors). Other value types are supported. See :erlang.halt/2 for how these work.

Next, add this module to your mix.exs's application description. This usually looks something like this:

  def application do
    [
      extra_applications: [:logger],
      mod: {Myapp.Main, []}
    ]
  end

Why does the module get added to :mod? Everything with Bakeware operates on OTP Releases. The macros in Bakeware.Script add the scaffolding to invoke your main/1 function from the release.

Link to this section Summary

Functions

Defines an app spec that will execute a script

Link to this section Types

Specs

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

Link to this section Functions

Link to this macro

__using__(opts)

View Source (macro)

Defines an app spec that will execute a script

Link to this macro

get_args(argc)

View Source (macro)
Link to this macro

result_to_halt(result)

View Source (macro)

Link to this section Callbacks

Specs

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