# `Juggernaut.CLI`
[🔗](https://github.com/holsee/juggernaut/blob/v0.4.0/lib/juggernaut/cli.ex#L1)

Runs a `Juggernaut.CLI.Task`: parses argv, prints `--help`, executes, reports errors
and returns the exit code (design notes §3).

Output goes through `Mix.shell/0`. An error is printed to stderr as `error: message`,
or, when the requested format is `agent` or `json`, as one JSON document on stdout:

    {"format":1,"kind":"error","exit_code":2,"error":{"type":"usage","message":"..."}}

# `error_document`

```elixir
@spec error_document(Juggernaut.Error.t(), Juggernaut.CLI.ExitCode.t()) ::
  Jason.OrderedObject.t()
```

The agent/JSON error document (see the agent output guide), keys in a stable order.

# `format_option`

```elixir
@spec format_option([atom()]) :: keyword()
```

The `--format` option for a task that offers `choices`. A `JUGGERNAUT_FORMAT` naming a
format this task does not offer is ignored, so one setting serves every task.

# `main`

```elixir
@spec main(module(), [String.t()]) :: :ok | no_return()
```

Runs `task` with `argv` and ends the Mix task with its exit code.

# `report`

```elixir
@spec report(Juggernaut.Error.t(), atom()) :: Juggernaut.CLI.ExitCode.t()
```

Prints `error` in `format` and returns its exit code.

# `run`

```elixir
@spec run(module(), [String.t()], Juggernaut.CLI.Task.ctx()) ::
  Juggernaut.CLI.ExitCode.t()
```

Runs `task` with `argv` in `ctx` and returns the exit code.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
