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

The behaviour of every `mix juggernaut*` task (design notes §3, §14).

A task is thin: it declares its flags (`c:cli/0`, see `Juggernaut.CLI.Options`) and
turns parsed options into an outcome (`c:execute/3`). `Juggernaut.CLI.main/2` does the
rest: parsing, `--help`, error reporting in the requested format and the exit code.

`ctx` carries the environment and the project root, so tasks are tested without
touching the real process environment, and optionally `plan_opts` for
`Juggernaut.Plan.resolve/3` (tests pass their own git runner).

# `ctx`

```elixir
@type ctx() :: %{
  :env =&gt; %{required(String.t()) =&gt; String.t()},
  :root =&gt; Path.t(),
  optional(:plan_opts) =&gt; keyword(),
  optional(:argv) =&gt; [String.t()],
  optional(:ansi) =&gt; boolean(),
  optional(:tty) =&gt; boolean(),
  optional(:progress) =&gt; (String.t() -&gt; term()),
  optional(:pool) =&gt; (map() -&gt; {:ok, pid()} | {:error, Juggernaut.Error.t()})
}
```

Optional keys: `ansi`, whether human output may be coloured; `tty`, whether stderr is a
terminal (the live progress line is redrawn); `progress`, called with each stderr line
when stderr is not a terminal; `pool`, the server's pool provider (`Juggernaut.Engine`).

# `outcome`

```elixir
@type outcome() ::
  :ok | {:ok, Juggernaut.CLI.ExitCode.t()} | {:error, Juggernaut.Error.t()}
```

# `cli`

```elixir
@callback cli() :: keyword()
```

The task's option spec (`Juggernaut.CLI.Options`).

# `execute`

```elixir
@callback execute(opts :: keyword(), args :: [String.t()], ctx()) :: outcome()
```

Runs the task with parsed options and positional arguments.

---

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