MCPcopy Index your code
hub / github.com/coder/coder / inOptionSet

Function inOptionSet

codersdk/richparameters.go:125–153  ·  view source on GitHub ↗

inOptionSet returns if the value given is in the set of options for a parameter.

(richParameter TemplateVersionParameter, value string)

Source from the content-addressed store, hash-verified

123
124// inOptionSet returns if the value given is in the set of options for a parameter.
125func inOptionSet(richParameter TemplateVersionParameter, value string) bool {
126 optionValues := make([]string, 0, len(richParameter.Options))
127 for _, option := range richParameter.Options {
128 optionValues = append(optionValues, option.Value)
129 }
130
131 // If the type is `list(string)` and the form_type is `multi-select`, then we check each individual
132 // value in the list against the option set.
133 isMultiSelect := richParameter.Type == provider.OptionTypeListString && richParameter.FormType == string(provider.ParameterFormTypeMultiSelect)
134
135 if !isMultiSelect {
136 // This is the simple case. Just checking if the value is in the option set.
137 return slice.Contains(optionValues, value)
138 }
139
140 var checks []string
141 err := json.Unmarshal([]byte(value), &checks)
142 if err != nil {
143 return false
144 }
145
146 for _, check := range checks {
147 if !slice.Contains(optionValues, check) {
148 return false
149 }
150 }
151
152 return true
153}
154
155func findBuildParameter(params []WorkspaceBuildParameter, parameterName string) (*WorkspaceBuildParameter, bool) {
156 if params == nil {

Callers 2

Test_inOptionSetFunction · 0.85
validateBuildParameterFunction · 0.85

Calls 2

ContainsFunction · 0.92
UnmarshalMethod · 0.45

Tested by 1

Test_inOptionSetFunction · 0.68