MCPcopy Create free account
hub / github.com/OctopusDeploy/cli / getVariable

Function getVariable

pkg/cmd/project/variables/update/update.go:182–212  ·  view source on GitHub ↗
(opts *UpdateOptions, project *projects.Project, projectVariables *variables.VariableSet)

Source from the content-addressed store, hash-verified

180}
181
182func getVariable(opts *UpdateOptions, project *projects.Project, projectVariables *variables.VariableSet) (*variables.Variable, error) {
183 var variable *variables.Variable
184 var err error
185 if opts.Id.Value != "" {
186 possibleVariables := util.SliceFilter(projectVariables.Variables, func(v *variables.Variable) bool {
187 return strings.EqualFold(v.ID, opts.Id.Value)
188 })
189
190 if len(possibleVariables) == 0 {
191 return nil, fmt.Errorf("cannot find variable with id '%s'", opts.Id.Value)
192 } else if len(possibleVariables) > 1 {
193 return nil, fmt.Errorf("'%s' has matched multiple variables", opts.Id.Value)
194 } else {
195 variable = possibleVariables[0]
196 }
197 } else {
198 possibleVariables := util.SliceFilter(projectVariables.Variables, func(v *variables.Variable) bool {
199 return strings.EqualFold(v.Name, opts.Name.Value)
200 })
201
202 if len(possibleVariables) == 0 {
203 return nil, fmt.Errorf("cannot find variable with name '%s'", opts.Name.Value)
204 } else if len(possibleVariables) > 1 {
205 return nil, fmt.Errorf("'%s' has multiple values, supply '%s' flag", possibleVariables[0].Name, FlagId)
206 } else {
207 variable = possibleVariables[0]
208 }
209 }
210
211 return variable, err
212}
213
214func PromptMissing(opts *UpdateOptions) error {
215 var project *projects.Project

Callers 2

updateRunFunction · 0.85
PromptMissingFunction · 0.85

Calls 1

SliceFilterFunction · 0.92

Tested by

no test coverage detected