ParseLangFlag validates and canonicalizes a --lang value, shared by config and profile so every entry point honors one contract. Empty is unset (no-op); a non-empty value must resolve via i18n.Parse or it errors.
(raw string)
| 14 | // and profile so every entry point honors one contract. Empty is unset (no-op); |
| 15 | // a non-empty value must resolve via i18n.Parse or it errors. |
| 16 | func ParseLangFlag(raw string) (i18n.Lang, error) { |
| 17 | if raw == "" { |
| 18 | return "", nil |
| 19 | } |
| 20 | lang, ok := i18n.Parse(raw) |
| 21 | if !ok { |
| 22 | return "", errs.NewValidationError(errs.SubtypeInvalidArgument, |
| 23 | "invalid --lang %q; valid values: %s", |
| 24 | raw, strings.Join(i18n.Codes(), ", ")). |
| 25 | WithParam("--lang") |
| 26 | } |
| 27 | return lang, nil |
| 28 | } |
no test coverage detected