# `ExQuality.OutputCollector`
[🔗](https://github.com/riddler/ex_quality/blob/v0.15.0/lib/ex_quality/output_collector.ex#L1)

Collects command output without streaming to console.

Implements the Collectable protocol for use with System.cmd/3's
:into option. Stores all output in memory for later retrieval.

## Example

    collector = ExQuality.OutputCollector.new()
    {_output, _exit_code} = System.cmd("mix", ["compile"], into: collector)
    output = ExQuality.OutputCollector.get_output(collector)

## Watching output as it arrives

A collector can also be given an `:on_line` handler, called with each
complete line as the command produces it:

    collector = ExQuality.OutputCollector.new(on_line: &IO.puts/1)

A stage whose tool can stall for minutes needs this to report progress while
it happens; the collected output is only available once the command has
exited. Lines are reassembled here because a chunk arrives at whatever
boundary the port gives it, which is rarely a line.

# `t`

```elixir
@type t() :: %ExQuality.OutputCollector{pid: pid()}
```

# `get_output`

```elixir
@spec get_output(t()) :: String.t()
```

Retrieves the collected output as a binary string.

# `new`

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

Creates a new output collector.

## Options

- `:on_line` - a one-argument function called with each complete line of
  output as it arrives, without its trailing newline.

---

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