View Source Clik (Clik v0.2.1)

Link to this section Summary

Types

Raw args from CLI

Error during arg parsing or command dispatch

Execution result

Functions

CLI execution entry point.

Link to this section Types

@type argv() :: [] | [String.t()]

Raw args from CLI

@type error() ::
  {:missing_option, atom()}
  | {:unknown_command, atom()}
  | {:unknown_options, [String.t()]}
  | {:error, :missing_command}
  | {:error, atom()}

Error during arg parsing or command dispatch

@type result() :: :ok | error()

Execution result

Link to this section Functions

Link to this function

run(config, args, env)

View Source (since 0.1.0)

CLI execution entry point.

Parses CLI args based on the configuration and calls the correct command. run/2 should be called from the main function.

example

Example

defmodule MyCLIApp do
  alias Clik.Configuration

  def main(args) do
    config =
      Configuration.add_command!(%Configuration{}, Command.new!(:default, MyCLIApp.DefaultCommand))
    case Clik.run(config, args) do
      :ok ->
        :erlang.halt(0)
      {:error, reason} ->
        :erlang.halt(1)
  end
end