DalaDev.Output (dala_dev v0.4.0)

Copy Markdown View Source

Centralized output helpers for all dala_dev tasks and modules.

All user-facing output should go through this module instead of raw IO.puts/Mix.shell().info so that:

  • ANSI styling is consistent (and disabled automatically when not a TTY)
  • --quiet suppresses non-essential output
  • --json machine-readable output is possible for scripting/agents

Semantic helpers:

DalaDev.Output.step("Deploying", "Pixel 8")
DalaDev.Output.success("pushed 42 BEAMs")
DalaDev.Output.warn("OTP cache is stale")
DalaDev.Output.error("adb not found")
DalaDev.Output.hint("Run `mix dala.doctor` to diagnose")

Timing helper for long operations:

DalaDev.Output.timed("Deployed to Pixel 8", fn ->
  Deployer.deploy_all()
end)

Summary

Functions

Configures output mode. Called once at the top of each Mix task.

Formats a byte count as a human-readable string.

Formats elapsed time from :timer.tc microseconds as a human string. Public for testing.

Info line (suppressed in quiet mode).

Returns true if --json was set via configure/1.

Returns true if --quiet was set via configure/1.

Prints a step header, e.g. ==> Deploying to devices.

Runs fun, printing <label>... done (1.2s) on success or <label>... failed (3.4s) on raise. Returns the fun's result.

Types

level()

@type level() :: :debug | :info | :success | :warn | :error | :hint

Functions

configure(opts \\ [])

@spec configure(keyword()) :: :ok

Configures output mode. Called once at the top of each Mix task.

Options

  • :quiet — when true, only errors are printed
  • :json — when true, structured results should be emitted as JSON (tasks opt in individually; see json?/0)

error(message)

@spec error(String.t()) :: :ok | nil

format_bytes(bytes)

@spec format_bytes(non_neg_integer()) :: String.t()

Formats a byte count as a human-readable string.

format_elapsed(microseconds)

@spec format_elapsed(non_neg_integer()) :: String.t()
@spec format_elapsed(non_neg_integer()) :: String.t()
@spec format_elapsed(non_neg_integer()) :: String.t()

Formats elapsed time from :timer.tc microseconds as a human string. Public for testing.

hint(message)

@spec hint(String.t()) :: :ok | nil

info(message)

@spec info(String.t()) :: :ok | nil

Info line (suppressed in quiet mode).

json?()

@spec json?() :: boolean()

Returns true if --json was set via configure/1.

quiet?()

@spec quiet?() :: boolean()

Returns true if --quiet was set via configure/1.

step(label, detail \\ nil)

@spec step(String.t(), String.t() | nil) :: :ok

Prints a step header, e.g. ==> Deploying to devices.

success(message)

@spec success(String.t()) :: :ok | nil

timed(label, fun)

@spec timed(String.t(), (-> term())) :: term()

Runs fun, printing <label>... done (1.2s) on success or <label>... failed (3.4s) on raise. Returns the fun's result.

warn(message)

@spec warn(String.t()) :: :ok | nil