Auto-Derivation & Enrichers¶
BOA automatically derives flag names, environment variables, and other metadata from your struct fields. This is done through enrichers - functions that process parameters during initialization.
ParamEnrich Field¶
The ParamEnrich field controls which enricher is used:
| Value | Behavior |
|---|---|
nil |
Uses ParamEnricherDefault (enriches everything including env vars) |
ParamEnricherDefault |
Explicit default: derives names, short flags, env vars, and bool defaults |
ParamEnricherNone |
No enrichment - you must specify everything via struct tags |
Default Behavior¶
By default (when ParamEnrich is nil), BOA applies ParamEnricherDefault, which includes:
| Enricher | What it does |
|---|---|
ParamEnricherName |
Converts MyParam → --my-param (kebab-case) |
ParamEnricherShort |
Auto-assigns -m from first char (skips conflicts, reserves -h) |
ParamEnricherEnv |
Generates MY_PARAM from flag name (UPPER_SNAKE_CASE) |
ParamEnricherBool |
Sets default: false for boolean params |
Example - this struct:
Automatically gets:
--server-host (env: SERVER_HOST, required)
--max-retries (env: MAX_RETRIES, required)
--verbose (env: VERBOSE, default: false)
Custom Enrichers¶
You can compose your own enricher to change the default behavior.
Disable Auto Env Vars¶
Prefix Env Vars¶
This turns MY_PARAM into MYAPP_MY_PARAM.
Disable Auto Short Flags¶
Disable All Enrichment¶
With no enrichment, you must specify everything via struct tags:
Available Enrichers¶
| Enricher | Description |
|---|---|
ParamEnricherDefault |
Combines Name + Short + Env + Bool |
ParamEnricherName |
Derives flag name from field name |
ParamEnricherShort |
Auto-assigns short flags |
ParamEnricherEnv |
Derives env var from flag name |
ParamEnricherEnvPrefix(prefix) |
Adds prefix to env vars |
ParamEnricherBool |
Sets false default for booleans |
ParamEnricherCombine(...) |
Combines multiple enrichers |
Override Auto-Derived Values¶
Struct tags always take precedence over enrichers: