# Mix v1.10.3 Mix.Shell.Process View Source

Mix shell that uses the current process mailbox for communication.

This module provides a Mix shell implementation that uses the current process mailbox for communication instead of IO.

As an example, when `Mix.shell().info("hello")` is called, the following message will be sent to the calling process:

    {:mix_shell, :info, ["hello"]}

This is mainly useful in tests, allowing us to assert if given messages were received or not instead of performing checks on some captured IO. Since we need to guarantee a clean slate between tests, there is also a `flush/1` function responsible for flushing all `:mix_shell` related messages from the process inbox.

## Examples

    Mix.shell().info("hello")

    receive do
      {:mix_shell, :info, [msg]} -> msg
    end
    #=> "hello"

    send(self(), {:mix_shell_input, :prompt, "Pretty cool"})
    Mix.shell().prompt?("How cool was that?!")
    #=> "Pretty cool"

# Link to this section Summary

## Functions

cmd(command, opts \\ [])

Executes the given command and forwards its messages to the current process.

error(message)

Forwards the error to the current process.

flush(callback \\ fn x -> x end)

Flushes all `:mix_shell` and `:mix_shell_input` messages from the current process.

info(message)

Forwards the message to the current process.

print_app()

Prints the current application if it was not printed yet.

prompt(message)

Forwards the message to the current process.

yes?(message)

Forwards the message to the current process.

# Link to this section Functions

Link to this function

# cmd(command, opts \\ [])

View Source

Executes the given command and forwards its messages to the current process.

Link to this function

# error(message)

View Source

Forwards the error to the current process.

Link to this function

# flush(callback \\ fn x -> x end)

View Source

Flushes all `:mix_shell` and `:mix_shell_input` messages from the current process.

If a callback is given, it is invoked for each received message.

## Examples

    flush(&IO.inspect/1)

Link to this function

# info(message)

View Source

Forwards the message to the current process.

Link to this function

# print_app()

View Source

Prints the current application if it was not printed yet.

Link to this function

# prompt(message)

View Source

Forwards the message to the current process.

It also checks the inbox for an input message matching:

    {:mix_shell_input, :prompt, value}

If one does not exist, it will abort since there was no shell process inputs given. `value` must be a string.

## Examples

The following will answer with `"Meg"` to the prompt `"What's your name?"`:

    # The response is sent before calling prompt/1 so that prompt/1 can read it
    send(self(), {:mix_shell_input, :prompt, "Meg"})
    Mix.shell().prompt("What's your name?")

Link to this function

# yes?(message)

View Source

Forwards the message to the current process.

It also checks the inbox for an input message matching:

    {:mix_shell_input, :yes?, value}

If one does not exist, it will abort since there was no shell process inputs given. `value` must be `true` or `false`.

## Example

    # Send the response to self() first so that yes?/1 will be able to read it
    send(self(), {:mix_shell_input, :yes?, true})
    Mix.shell().yes?("Are you sure you want to continue?")