# `Mix.Shell`
[🔗](https://github.com/elixir-lang/elixir/blob/7ff272706afc522e74121493b7166719985cb099/lib/mix/lib/mix/shell.ex#L5)

Defines `Mix.Shell` contract.

# `cmd_opts`

```elixir
@type cmd_opts() :: [
  {:print_app, boolean()}
  | {:stderr_to_stdout, boolean()}
  | {:quiet, boolean()}
  | {:env, [{String.t(), String.t()}]}
  | {:cd, String.t()}
  | {atom(), term()}
]
```

# `stream_cmd_opts`

```elixir
@type stream_cmd_opts() :: [
  {:cd, String.t()}
  | {:stderr_to_stdout, boolean()}
  | {:use_stdio, boolean()}
  | {:env, [{String.t(), String.t()}]}
  | {:quiet, boolean()}
  | {atom(), term()}
]
```

# `yes_opts`

```elixir
@type yes_opts() :: [{:default, :yes | :no} | {atom(), term()}]
```

# `cmd`

```elixir
@callback cmd(command :: String.t()) :: integer()
```

Executes the given command and returns its exit status.

Shortcut for `c:cmd/2` with empty options.

# `cmd`

```elixir
@callback cmd(command :: String.t(), options :: cmd_opts()) :: integer()
```

Executes the given command and returns its exit status.

## Options

This callback should support the following options:

  * `:print_app` - when `false`, does not print the app name
    when the command outputs something

  * `:stderr_to_stdout` - when `false`, does not redirect
    stderr to stdout

  * `:quiet` - when `true`, do not print the command output

  * `:env` - environment options to the executed command

  * `:cd` *(since v1.11.0)* - the directory to run the command in

All the built-in shells support these.

# `error`

```elixir
@callback error(message :: IO.ANSI.ansidata()) :: :ok
```

Prints the given ANSI error to the shell.

# `info`

```elixir
@callback info(message :: IO.ANSI.ansidata()) :: :ok
```

Prints the given ANSI message to the shell.

# `print_app`

```elixir
@callback print_app() :: :ok
```

Prints the current application to the shell if
it was not printed yet.

# `prompt`

```elixir
@callback prompt(message :: binary()) :: binary()
```

Prompts the user for input.

# `yes?`

```elixir
@callback yes?(message :: binary()) :: boolean()
```

Prompts the user for confirmation.

Shortcut for `yes?/2` with empty options.

# `yes?`

```elixir
@callback yes?(message :: binary(), options :: yes_opts()) :: boolean()
```

Prompts the user for confirmation.

## Options

  * `:default` - `:yes` or `:no` (the default is `:yes`)

# `cmd`

```elixir
@spec cmd(String.t() | {String.t(), [String.t()]}, stream_cmd_opts(), (binary() -&gt;
                                                                   term())) ::
  exit_status :: non_neg_integer()
```

Executes the given `command` and invokes the `callback` for the streamed response.

`command` is either a string, to be executed as a `System.shell/2` command,
or a `{executable, args}` to be executed via `System.cmd/3`.

`callback` takes the output data of the command. Its return value is ignored.

This function is most commonly used by `Mix.Shell` implementations but can
also be invoked directly.

## Options

  * `:cd` *(since v1.11.0)* - the directory to run the command in

  * `:stderr_to_stdout` - redirects stderr to stdout, defaults to `true`, unless `:use_stdio` is set to `false`

  * `:use_stdio` - controls whether the command should use `stdin` / `stdout` / `stderr`, defaults to `true`

  * `:env` - a list of environment variables, defaults to `[]`

  * `:quiet` - overrides the callback to no-op

# `printable_app_name`

```elixir
@spec printable_app_name() :: atom() | nil
```

Returns the printable app name.

This function returns the current application name,
but only if the application name should be printed.

Calling this function automatically toggles its value
to `false` until the current project is re-entered. The
goal is to avoid printing the application name
multiple times.

---

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