# `WardrikDaemon.CLI.Context`

What every command runs with: the directories, the environment, the deployment's org, the
terminal it writes to, the name it was typed as, and whether it prints JSON.

# `t`

```elixir
@type t() :: %WardrikDaemon.CLI.Context{
  dirs: WardrikDaemon.Dirs.t(),
  env: %{required(String.t()) =&gt; String.t()},
  json?: boolean(),
  org: String.t(),
  program: String.t(),
  terminal: WardrikDaemon.CLI.Terminal.t()
}
```

# `agent`

```elixir
@spec agent(t(), String.t()) :: String.t()
```

Returns the ID `name` names: `name` itself if it holds an org, or else `name` under the deployment's org.

# `call`

```elixir
@spec call(t(), String.t(), map()) :: {:ok, map() | nil} | {:error, String.t()}
```

Runs the operation `id` on the daemon. Returns its answer, or the reason it failed.

# `called`

```elixir
@spec called({:ok, term()} | WardrikDaemon.Client.error()) ::
  {:ok, term()} | {:error, String.t()}
```

Returns an operation's answer, with its error as a message.

# `client`

```elixir
@spec client(t()) :: {:ok, WardrikDaemon.Client.t()} | {:error, String.t()}
```

Returns the client that reaches the daemon: from `WARDRIK_URL` and `WARDRIK_TOKEN` if both are set, or from `cli_token`.

# `done`

```elixir
@spec done(t(), term(), Owl.Data.t()) :: :ok
```

Writes `said` once a change is done, or the answer as JSON if the command was given `--json`.

# `new`

```elixir
@spec new(%{required(String.t()) =&gt; String.t()}) :: t()
```

Returns the context for `env`, the environment. The org is `config.yaml`'s `org`, or `default`.

# `owner`

```elixir
@spec owner(t(), map(), String.t()) :: String.t()
```

Returns the owner `flags` name: `--org`, or `--user` in the deployment's org, or else `default`.

# `put`

```elixir
@spec put(map(), String.t(), term()) :: map()
```

Puts `value` in `map` under `key`, unless it's `nil`.

# `puts`

```elixir
@spec puts(t(), Owl.Data.t()) :: :ok
```

Writes `data` to the command's terminal.

# `show`

```elixir
@spec show(t(), term(), (term() -&gt; term())) :: :ok
```

Writes `answer` as JSON if the command was given `--json`. Otherwise calls `shown` with it.

---

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