kv prints a key/value line inside a section with automatic coloring. key is an i18n-translated label (the caller passes i18n.T(...)) or a literal env var name when no translation applies. Coloring rules: - "[SET]" / enabled / on → green (explicitly configured truthy) - "[NOT SET]" / disabled
(prefix, key, value string)
| 196 | // fallback from the env-default registry) |
| 197 | // - everything else → gray (user-set value) |
| 198 | func kv(prefix, key, value string) { |
| 199 | valueColor := ColorGray |
| 200 | display := strings.TrimSpace(value) |
| 201 | enabledLabel := i18n.T("cfg.val.enabled") |
| 202 | disabledLabel := i18n.T("cfg.val.disabled") |
| 203 | defaultTag := i18n.T("cfg.val.default_tag") |
| 204 | |
| 205 | // Default-value path: strip the sentinel, render in cyan with a |
| 206 | // trailing "(default)" tag so the line visibly distinguishes from |
| 207 | // user-set values without losing the actual value. |
| 208 | if strings.HasPrefix(display, defaultMarker) { |
| 209 | display = strings.TrimPrefix(display, defaultMarker) |
| 210 | fmt.Printf("%s%s %s %s\n", |
| 211 | prefix, |
| 212 | colorize(fmt.Sprintf("%-32s", key+":"), ColorCyan), |
| 213 | colorize(display, ColorCyan), |
| 214 | colorize(defaultTag, ColorGray)) |
| 215 | return |
| 216 | } |
| 217 | |
| 218 | switch { |
| 219 | case display == "": |
| 220 | display = i18n.T("cfg.val.default") |
| 221 | case strings.Contains(display, "[SET]") || display == enabledLabel || display == i18n.T("cfg.val.on"): |
| 222 | valueColor = ColorGreen |
| 223 | case strings.Contains(display, "[NOT SET]") || |
| 224 | display == i18n.T("cfg.val.not_set") || |
| 225 | display == i18n.T("cfg.val.none") || |
| 226 | display == disabledLabel || |
| 227 | display == i18n.T("cfg.val.off"): |
| 228 | valueColor = ColorYellow |
| 229 | } |
| 230 | fmt.Printf("%s%s %s\n", |
| 231 | prefix, |
| 232 | colorize(fmt.Sprintf("%-32s", key+":"), ColorCyan), |
| 233 | colorize(display, valueColor)) |
| 234 | } |
| 235 | |
| 236 | // envOr returns the env value, or the registered runtime default tagged |
| 237 | // with defaultMarker so kv() can color it as "(default)", or the |
no test coverage detected