MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / ParseAndValidateOpts

Function ParseAndValidateOpts

app/cli/cmd/registered_integration_add.go:82–102  ·  view source on GitHub ↗
(opts []string, schema *action.JSONSchema)

Source from the content-addressed store, hash-verified

80}
81
82func 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

Callers 2

Calls 2

ParseKeyValOptsFunction · 0.85
ValidateMethod · 0.45

Tested by

no test coverage detected