(asker question.Asker, message string, variableType string, defaultValue string, isRequired bool, isSensitive bool, displaySettings *resources.DisplaySettings)
| 203 | } |
| 204 | |
| 205 | func AskVariableSpecificPrompt(asker question.Asker, message string, variableType string, defaultValue string, isRequired bool, isSensitive bool, displaySettings *resources.DisplaySettings) (string, error) { |
| 206 | var askOpt survey.AskOpt = func(options *survey.AskOptions) error { |
| 207 | if isRequired { |
| 208 | options.Validators = append(options.Validators, survey.Required) |
| 209 | } |
| 210 | return nil |
| 211 | } |
| 212 | |
| 213 | // work out what kind of prompt to use |
| 214 | var controlType resources.ControlType |
| 215 | if displaySettings != nil && displaySettings.ControlType != "" { |
| 216 | controlType = displaySettings.ControlType |
| 217 | } else { // infer the control type based on other flags |
| 218 | // The shape of the data model allows for the possibility of a sensitive multi-line or sensitive combo-box |
| 219 | // variable. However, the web portal doesn't implement any of these, the only sensitive thing it supports |
| 220 | // is single-line text, so we can simplify our logic here. |
| 221 | if variableType == "Sensitive" || isSensitive { |
| 222 | // From comment in server: |
| 223 | // variable.IsSensitive is Kept for backwards compatibility. New way is to use variable.Type=VariableType.Sensitive |
| 224 | controlType = resources.ControlTypeSensitive |
| 225 | } else { |
| 226 | controlType = resources.ControlTypeSingleLineText |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | switch controlType { |
| 231 | case resources.ControlTypeSingleLineText, "": // if control type is not explicitly set it means single line text. |
| 232 | var response string |
| 233 | err := asker(&survey.Input{ |
| 234 | Message: message, |
| 235 | Default: defaultValue, |
| 236 | }, &response, askOpt) |
| 237 | return response, err |
| 238 | |
| 239 | case resources.ControlTypeSensitive: |
| 240 | var response string |
| 241 | err := asker(&survey.Password{ |
| 242 | Message: message, |
| 243 | }, &response, askOpt) |
| 244 | return response, err |
| 245 | |
| 246 | case resources.ControlTypeMultiLineText: // not clear if the server ever does this |
| 247 | var response string |
| 248 | err := asker(&surveyext.OctoEditor{ |
| 249 | Editor: &survey.Editor{ |
| 250 | Message: "message", |
| 251 | FileName: "*.txt", |
| 252 | }, |
| 253 | Optional: !isRequired}, &response) |
| 254 | return response, err |
| 255 | |
| 256 | case resources.ControlTypeSelect: |
| 257 | if displaySettings == nil { |
| 258 | return "", cliErrors.NewArgumentNullOrEmptyError("displaySettings") // select needs actual display settings |
| 259 | } |
| 260 | reverseLookup := make(map[string]string, len(displaySettings.SelectOptions)) |
| 261 | optionStrings := make([]string, 0, len(displaySettings.SelectOptions)) |
| 262 | var displayNameForDefaultValue string |
no outgoing calls