View Source Tux.Exit behaviour (Tux v0.4.0)

Routines for stopping the VM with an appropriate exit code from command modules.

This logic in this module is automatically injected by dispatcher and command modules, however its callbacks can be overwritten for custom needs:

defmodule MyCmd do
  use Tux.Command

  @impl true
  def exit(env, result), do: ...stop the VM...
end

Summary

Callbacks

Shutdown the VM using an exit code extracted or derived from the given command result.

Functions

Return the correponding exit code for a given command result.

Callbacks

exit(env, result)

@callback exit(env :: Tux.Env.t(), result :: Tux.Result.t()) :: :ok | no_return()

Shutdown the VM using an exit code extracted or derived from the given command result.

Functions

code(arg1)

@spec code(result :: Tux.Result.t()) :: integer() | no_return()

Return the correponding exit code for a given command result.

The returned exit code will be determined from the given result value, which ought to be following the Tux.Result format, however when non-Tux.Result values are given, the exit code will always be determined to be 0.

Examples

iex> Tux.Exit.code(:ok)
0

iex> Tux.Exit.code({:ok, "some term"})
0

iex> Tux.Exit.code(:error)
1

iex> Tux.Exit.code({:error, %{exitcode: 10}})
10

iex> Tux.Exit.code({:error, "some error"})
1

iex> Tux.Exit.code(:anything_else_returns_0)
0