Botica.Batteries.Command (Botica v2.2.0)

Copy Markdown View Source

Shared command runner for the batteries.

Every battery (Disk, Memory, PostgreSQL, Redis) shells out to an external tool — df, cat /proc/meminfo, pg_isready, redis-cli, sudo systemctl. They used to do that through Trebejo.Util.run_cmd_legacy/3, but trebejo is deliberately not in deps (botica must resolve and build without it), so the Code.ensure_loaded? guard was always false and every battery returned the placeholder {"trebejo not loaded", 127}. The checks degraded to noise instead of actually reporting anything.

This module keeps the Trebejo path for anyone who does have it loaded, and falls back to System.cmd/3 otherwise, so a battery always produces a real answer. The return shape matches Trebejo's: {output_string, exit_code}.

Options

  • :timeout — milliseconds, default 5_000
  • :env — environment map, default %{}
  • :cd — working directory, default "."
  • :stderr_to_stdout — default false

Summary

Functions

Runs cmd with args, preferring Trebejo.Util.run_cmd_legacy/3 when that module is loaded and exporting the function, and falling back to System.cmd/3 otherwise.

Functions

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

@spec run(String.t(), [String.t()], keyword()) :: {String.t(), integer()}

Runs cmd with args, preferring Trebejo.Util.run_cmd_legacy/3 when that module is loaded and exporting the function, and falling back to System.cmd/3 otherwise.

Returns {output, exit_code} where output is an empty string when the binary could not be spawned at all (:enoent) and exit_code is 127, matching the shell convention for "command not found".