Assert

assert_not_empty

Assert that a value is not empty. Prints an error and returns 1 if the value is empty or unset.

Example

assert_not_empty "${MY_VAR}" "MY_VAR"

Arguments

  • $1 (string): The value to check
  • $2 (string): Human-readable name for the error message

Exit codes

  • 0: Value is non-empty; 1 Value is empty

assert_is_installed

Assert that a command exists in PATH.

Example

assert_is_installed curl

Arguments

  • $1 (string): Command name

Exit codes

  • 0: Command found; 1 Command missing

assert_value_in_list

Assert that a value is one of an allowed list of values.

Example

assert_value_in_list "${ENV}" dev staging prod

Arguments

  • $1 (string): The value to check
  • ... (string): Allowed values (all arguments after $1)

Exit codes

  • 0: Value is in list; 1 Value not in list

assert_exactly_one_of

Assert that exactly one of the given values is non-empty. Useful for validating mutually exclusive options.

Example

assert_exactly_one_of "${opt_a}" "${opt_b}" "${opt_c}"

Arguments

  • ... (string): Values to test (at least two required)

Exit codes

  • 0: Exactly one non-empty; 1 Zero or more than one non-empty