parseFromMap parses an option value from a map of allowed values
( ctx context.Context, p *Parser, o *options.Options, key string, m map[string]T, args ...string, )
| 286 | |
| 287 | // parseFromMap parses an option value from a map of allowed values |
| 288 | func parseFromMap[T comparable]( |
| 289 | ctx context.Context, |
| 290 | p *Parser, |
| 291 | o *options.Options, |
| 292 | key string, |
| 293 | m map[string]T, |
| 294 | args ...string, |
| 295 | ) error { |
| 296 | if err := p.ensureMaxArgs(ctx, key, args, 1); err != nil { |
| 297 | return err |
| 298 | } |
| 299 | |
| 300 | v, ok := m[args[0]] |
| 301 | if !ok { |
| 302 | return newInvalidArgumentError(ctx, key, args[0], slices.Collect(maps.Keys(m))...) |
| 303 | } |
| 304 | |
| 305 | o.Set(key, v) |
| 306 | |
| 307 | return nil |
| 308 | } |
| 309 | |
| 310 | func (p *Parser) parseGravityType( |
| 311 | ctx context.Context, |
no test coverage detected