Parse validates a YAML document in memory. Exported so the TUI can validate as the user types.
(doc []byte)
| 116 | // Parse validates a YAML document in memory. Exported so the TUI can |
| 117 | // validate as the user types. |
| 118 | func Parse(doc []byte) (*Config, error) { |
| 119 | var c Config |
| 120 | if err := yaml.Unmarshal(doc, &c); err != nil { |
| 121 | return nil, fmt.Errorf("config: parse yaml: %w", err) |
| 122 | } |
| 123 | if err := c.Validate(); err != nil { |
| 124 | return nil, err |
| 125 | } |
| 126 | return &c, nil |
| 127 | } |
| 128 | |
| 129 | // Validate checks invariants and sets defaults in-place. |
| 130 | func (c *Config) Validate() error { |