GitHoox.Cmd (GitHoox v0.3.0)

Copy Markdown View Source

Drop-in replacement for System.cmd/3 that streams the spawned process's combined stdout/stderr to :stdio as each chunk arrives, while still accumulating the full output for the caller.

Return shape matches System.cmd/3{output, exit_status} — so call sites can keep using the existing {out, 0} / {out, code} patterns.

Options

  • :env — env vars as a list of {key, value} string tuples, same as System.cmd/3.
  • :stream — explicit override of the streaming behaviour. When omitted, falls back to Application.get_env(:git_hoox, :stream_output, true). Tests set the application env to false in test/test_helper.exs so they keep clean output; real mix git_hoox.run invocations stream by default.
  • :device — IO device to write streamed chunks to. Default :stdio. Useful for redirecting to :stderr or to a captured device in tests.

Hook timeouts are still enforced one layer up by GitHoox.Runner. When the runner brutally kills the Task that owns the port, BEAM closes the port and the OS child process gets SIGTERM.

Summary

Functions

Run command with args, returning {output, exit_status}.

Types

cmd_opts()

@type cmd_opts() :: [
  env: [{String.t(), String.t()}],
  stream: boolean(),
  device: IO.device()
]

Functions

run(command, args, opts \\ [])

@spec run(String.t(), [String.t()], cmd_opts()) :: {String.t(), non_neg_integer()}

Run command with args, returning {output, exit_status}.

Raises RuntimeError if command cannot be resolved on $PATH.