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

What `mix juggernaut` writes while a run goes and when it ends (design notes §5): a pure
reducer over the engine's run events (`t:Juggernaut.View.Stream.event/0`).

  * `--stream`: every event becomes its NDJSON lines on stdout
    (`Juggernaut.View.Stream`); with `--format agent` the last line holds the agent
    document (event `report`). Nothing else goes to stdout.
  * `human`: the live view (`Juggernaut.View.Live`): progress on stderr, each survivor
    as it is found and the summary on stdout.
  * `agent`, `json`, `markdown`, `github`: the live view's stderr lines only; the
    format's document is written once, at the end (`document/2`), so stdout holds that
    document alone.

`handle/3` returns the writes, in order, as `{:stdout | :stderr, iodata}`.

# `format`

```elixir
@type format() :: :human | :agent | :json | :markdown | :github
```

# `t`

```elixir
@type t() :: %Juggernaut.CLI.RunOutput{
  format: format(),
  live: Juggernaut.View.Live.t(),
  opts: Juggernaut.View.options(),
  run_id: String.t() | nil,
  stream?: boolean()
}
```

# `write`

```elixir
@type write() :: {:stdout | :stderr, iodata()}
```

# `document`

```elixir
@spec document(t(), Juggernaut.Run.t()) :: iodata()
```

The whole document of `run` in the output's format (for `--output PATH`).

# `final`

```elixir
@spec final(t(), Juggernaut.Run.t()) :: iodata()
```

What to write to stdout once the run has finished: nothing for `human` and for
`--stream` (both already wrote it), else the format's document.

# `handle`

```elixir
@spec handle(t(), Juggernaut.View.Stream.event(), non_neg_integer()) ::
  {[write()], t()}
```

Takes one event at `t_ms` (milliseconds since the run started).

# `new`

```elixir
@spec new(format(), keyword()) :: t()
```

An output for `format`. Options: `stream` (NDJSON, default false), `tty` (redraw the
progress line; never with `stream`) and the view options of `Juggernaut.View`.

# `put_options`

```elixir
@spec put_options(t(), keyword()) :: t()
```

Replaces view options (for example the sources, once the plan names the files).

---

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