validateTheme reports whether ref names a loadable theme. It is used to fail fast on an explicit --theme value, listing the available themes so the user can correct a typo.
(ref string)
| 1117 | // fail fast on an explicit --theme value, listing the available themes so the |
| 1118 | // user can correct a typo. |
| 1119 | func validateTheme(ref string) error { |
| 1120 | if _, err := styles.LoadTheme(ref); err != nil { |
| 1121 | if refs, listErr := styles.ListThemeRefs(); listErr == nil && len(refs) > 0 { |
| 1122 | return fmt.Errorf("unknown theme %q; available themes: %s", ref, strings.Join(refs, ", ")) |
| 1123 | } |
| 1124 | return fmt.Errorf("unknown theme %q: %w", ref, err) |
| 1125 | } |
| 1126 | return nil |
| 1127 | } |
| 1128 | |
| 1129 | // applyTheme applies the theme, resolving it from the --theme flag, then the |
| 1130 | // user config, then the built-in default. |