resolveAgentLoadMode function

AgentLoadMode resolveAgentLoadMode({
  1. bool flagOmp = false,
  2. String? envMode,
  3. String? configMode,
})

Resolves the load mode for this boot: flag > env > config (issue #680 AC3 precedence). flagOmp is --omp; envMode the raw FA_AGENT_MODE value; configMode the raw agent.mode yaml value.

Throws ArgumentError naming the source when an env/config label is not one of agentLoadModeLabels — a typo must never silently boot the default mode.

Implementation

AgentLoadMode resolveAgentLoadMode({
  bool flagOmp = false,
  String? envMode,
  String? configMode,
}) {
  if (flagOmp) return AgentLoadMode.omp;
  final fromEnv = agentLoadModeFromLabel(envMode);
  if (envMode != null && envMode.isNotEmpty && fromEnv == null) {
    throw ArgumentError.value(
      envMode,
      'FA_AGENT_MODE',
      'unknown load mode (expected one of: ${agentLoadModeLabels.join(', ')})',
    );
  }
  if (fromEnv != null) return fromEnv;
  final fromConfig = agentLoadModeFromLabel(configMode);
  if (configMode != null && configMode.isNotEmpty && fromConfig == null) {
    throw ArgumentError.value(
      configMode,
      'agent.mode',
      'unknown load mode (expected one of: ${agentLoadModeLabels.join(', ')})',
    );
  }
  return fromConfig ?? AgentLoadMode.defaultMode;
}