(opts []string, schema *action.JSONSchema)
| 80 | } |
| 81 | |
| 82 | func ParseAndValidateOpts(opts []string, schema *action.JSONSchema) (map[string]any, error) { |
| 83 | // Parse |
| 84 | res, err := ParseKeyValOpts(opts, schema.Properties) |
| 85 | if err != nil { |
| 86 | return nil, fmt.Errorf("failed to parse options: %w", err) |
| 87 | } |
| 88 | |
| 89 | // Validate |
| 90 | if err = schema.Parsed.Validate(res); err != nil { |
| 91 | // If validation fails, print the schema table |
| 92 | var validationError *jsonschema.ValidationError |
| 93 | |
| 94 | // Prepare error message |
| 95 | if errors.As(err, &validationError) { |
| 96 | validationErrors := validationError.BasicOutput().Errors |
| 97 | return nil, errors.New(validationErrors[len(validationErrors)-1].Error) |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | return res, nil |
| 102 | } |
| 103 | |
| 104 | // ParseKeyValOpts performs two steps |
| 105 | // 1 - Split the options into key/value pairs |
no test coverage detected