(opts *CreateOptions)
| 149 | } |
| 150 | |
| 151 | func CreateRun(opts *CreateOptions) error { |
| 152 | if !opts.NoPrompt { |
| 153 | err := PromptMissing(opts) |
| 154 | if err != nil { |
| 155 | return err |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | project, err := opts.GetProjectCallback(opts.Project.Value) |
| 160 | if err != nil { |
| 161 | return err |
| 162 | } |
| 163 | |
| 164 | var projectVariables *variables.VariableSet |
| 165 | if project.IsVersionControlled && opts.GitRef.Value != "" { |
| 166 | projectVariables, err = opts.GetProjectVariablesByGitRef(opts.Space.GetID(), project.GetID(), opts.GitRef.Value) |
| 167 | } else { |
| 168 | projectVariables, err = opts.GetProjectVariables(project.GetID()) |
| 169 | } |
| 170 | if err != nil { |
| 171 | return err |
| 172 | } |
| 173 | |
| 174 | scope, err := sharedProjectVariable.ToVariableScope(projectVariables, opts.ScopeFlags, project) |
| 175 | if err != nil { |
| 176 | return err |
| 177 | } |
| 178 | |
| 179 | newVariable := variables.NewVariable(opts.Name.Value) |
| 180 | varType, err := mapVariableType(opts.Type.Value) |
| 181 | if err != nil { |
| 182 | return err |
| 183 | } |
| 184 | |
| 185 | newVariable.Type = varType |
| 186 | newVariable.Value = opts.Value.Value |
| 187 | newVariable.Scope = *scope |
| 188 | |
| 189 | if opts.IsPrompted.Value { |
| 190 | promptControlType, err := mapControlType(opts.PromptType.Value) |
| 191 | if err != nil { |
| 192 | return err |
| 193 | } |
| 194 | newVariable.Prompt = &variables.VariablePromptOptions{ |
| 195 | Description: opts.PromptDescription.Value, |
| 196 | Label: opts.PromptLabel.Value, |
| 197 | IsRequired: opts.PromptRequired.Value, |
| 198 | } |
| 199 | |
| 200 | selectOptions := parseSelectOptions(opts, promptControlType) |
| 201 | newVariable.Prompt.DisplaySettings = resources.NewDisplaySettings(promptControlType, selectOptions) |
| 202 | } |
| 203 | |
| 204 | if opts.GitRef.Value != "" { |
| 205 | _, err = opts.Client.ProjectVariables.AddSingleByGitRef(opts.Space.GetID(), project.GetID(), opts.GitRef.Value, newVariable) |
| 206 | } else { |
| 207 | _, err = opts.Client.Variables.AddSingle(project.GetID(), newVariable) |
| 208 | } |
no test coverage detected