Util.Env (fnord v0.9.38)

View Source

Utilities for interpreting environment variables used in fnord.

Provide canonical parsing helpers so different runtime contexts treat environment values consistently (escript, mix run, CI, etc.).

Reads consult a Services.Globals-scoped override before the real environment, so a process tree can see a different value than the VM at large (see put_override/2). In-VM env reads should always route through this module rather than System.get_env so they honor that scoping.

Summary

Functions

Delete the environment variable.

Return true when the provided environment value is considered truthy.

Set the environment variable to the given value.

Override var for the current Services.Globals scope (process tree). Reads through this module see the override; the real environment - and therefore subprocesses - do not. nil makes the variable appear unset.

Functions

cursor_rules_debug_enabled?()

@spec cursor_rules_debug_enabled?() :: boolean()

delete_env(var)

@spec delete_env(binary()) :: :ok

Delete the environment variable.

fetch_env(var)

@spec fetch_env(binary()) :: {:ok, binary()} | {:error, :not_set}

get_env(var, default \\ nil)

@spec get_env(binary(), any()) :: any()

looks_truthy?(env_var_name)

@spec looks_truthy?(binary()) :: boolean()

Return true when the provided environment value is considered truthy.

Recognizes the common truthy values (case-insensitive): "1", "true", and "yes". Returns false for nil, empty strings, and other values.

mcp_debug_enabled?()

@spec mcp_debug_enabled?() :: boolean()

put_env(var, value)

@spec put_env(binary(), binary()) :: :ok

Set the environment variable to the given value.

put_override(var, value)

@spec put_override(binary(), binary() | nil) :: :ok

Override var for the current Services.Globals scope (process tree). Reads through this module see the override; the real environment - and therefore subprocesses - do not. nil makes the variable appear unset.

This is the async-safe alternative to put_env/2 for tests: System env is VM-global, so a per-test put/delete races every concurrently running test, while an override dies with the test's process tree.