Shared utility functions used across the dala_dev codebase.
This module centralizes common operations to reduce duplication and ensure consistent behavior across modules.
Summary
Functions
Checks if ADB is available in the system PATH.
Checks if a command is available in the system PATH.
Compiles a regex pattern with the given options.
Ensures a directory exists, creating it if necessary.
Formats a byte size into a human-readable string.
Parses ADB devices output into a list of device identifiers.
Runs an ADB command for a specific device with timeout.
Safely runs an ADB command with timeout protection.
Functions
@spec adb_available?() :: boolean()
Checks if ADB is available in the system PATH.
Checks if a command is available in the system PATH.
Compiles a regex pattern with the given options.
Centralizes regex compilation to avoid duplicating Regex.compile!/2 calls
and provides a single place to handle compilation errors.
Examples
iex> DalaDev.Utils.compile_regex("hello\s+world")
~r/hello\s+world/
Ensures a directory exists, creating it if necessary.
Returns :ok on success, {:error, reason} on failure.
@spec format_bytes(non_neg_integer()) :: String.t()
Formats a byte size into a human-readable string.
Parses ADB devices output into a list of device identifiers.
Expects output from adb devices command.
@spec run_adb_for_device(String.t(), [String.t()], keyword()) :: {:ok, String.t()} | {:error, term()}
Runs an ADB command for a specific device with timeout.
Convenience wrapper that prepends -s <serial> to the arguments.
Safely runs an ADB command with timeout protection.
Returns {:ok, output} on success, {:error, reason} on failure.
Options
:timeout- timeout in milliseconds (default: 8000):stderr_to_stdout- whether to merge stderr (default: true)