Skip to content

Commit

Permalink
add support for overriding prefix (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
cschiewek authored Sep 27, 2021
1 parent bc46b1a commit e6f462d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ end

Foreperson has 2 configuration options:

`wait:`

The amount of time to pause before finalizing startup. This is useful if the configured process isn't instantly ready.
For example, if your elixir app uses `ecto` and you want to use `foreperson` to start a `postgres` instance, you can set a
wait time to ensure postgres is ready before `ecto` tries to connect.

`processes:`

A list of exertnal processes that you want to start. The syntax is the similar to [Phoenix endpoint watchers](https://hexdocs.pm/phoenix/Phoenix.Endpoint.html#module-runtime-configuration).
Expand All @@ -36,10 +30,17 @@ followed by a keyword list of options.

The available options are:
- `:wrap`: Use a [zombie process wrapper](https://hexdocs.pm/elixir/master/Port.html#module-zombie-operating-system-processes). Defaults to `true`.
- `:into`: Injects the result into the given collectable. Defaults to `Foreperson.stream(cmd)` where `cmd` is the name of the process.
- `:prefix`: String added as prefix to the processes output. Defaults to the key/command.
- `:into`: Injects the result into the given collectable. Defaults to `Foreperson.stream(prefix)`.
- `:stderr_to_stdout` - redirects stderr to stdout. Defaults to `true`.
- All the options available to [System.cmd/3](https://hexdocs.pm/elixir/System.html#cmd/3-options)

`wait:`

The amount of time to pause before finalizing startup. This is useful if the configured process isn't instantly ready.
For example, if your elixir app uses `ecto` and you want to use `foreperson` to start a `postgres` instance, you can set a
wait time to ensure postgres is ready before `ecto` tries to connect.

### Example
```elixir
config :foreperson,
Expand Down
2 changes: 1 addition & 1 deletion lib/foreperson/formatter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule Foreperson.Formatter do

defp into(formatter, prefix) do
fn
:ok, {:cont, x} -> IO.write(:stdio, (prefix && "👷[#{prefix}] ") <> x)
:ok, {:cont, x} -> IO.write(:stdio, "👷[#{prefix}] " <> x)
:ok, _ -> formatter
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/foreperson/process.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ defmodule Foreperson.Process do
def run(cmd, args) when is_list(args) do
{args, opts} = Enum.split_while(args, &is_binary(&1))
{wrap, opts} = Keyword.pop(opts, :wrap, true)
opts = Keyword.merge([into: Foreperson.stream(cmd), stderr_to_stdout: true], opts)
{prefix, opts} = Keyword.pop(opts, :prefix, cmd)
opts = Keyword.merge([into: Foreperson.stream(prefix), stderr_to_stdout: true], opts)

{args, cmd} =
case wrap do
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Foreperson.MixProject do
use Mix.Project

@version "0.1.3"
@version "0.1.4"
@source_url "https://github.com/cschiewek/foreperson"

def project do
Expand Down

0 comments on commit e6f462d

Please sign in to comment.