RunPrompt obtains the value of PromptHandler depending on the parameter's definition for the project config, there are multiple ways of obtaining the value values go into params depending on `Condition` as the highest precedence (Whether it gets this value) then follows this order to determine HOW
(projectParams map[string]string, envVarTranslationMap map[string]string)
| 142 | // 3. value: directly assigns a value to a parameter |
| 143 | // 4. prompt: requires users to select an option OR input a string |
| 144 | func (p PromptHandler) RunPrompt(projectParams map[string]string, envVarTranslationMap map[string]string) error { |
| 145 | var err error |
| 146 | var result string |
| 147 | |
| 148 | if p.Condition(projectParams) { |
| 149 | |
| 150 | // If we start printing below the bottom of the terminal screen, go back to the top |
| 151 | if currentLine+infoBoxHeight+1 > tm.Height() { |
| 152 | tm.Clear() |
| 153 | currentLine = infoBoxHeight |
| 154 | } |
| 155 | |
| 156 | // TODO: figure out scope of projectParams per project |
| 157 | // potentially dangerous to have cross module env leaking |
| 158 | // so if community module has an `execute: twitter tweet $ENV` |
| 159 | // it wouldnt leak things the module shouldnt have access to |
| 160 | if p.Parameter.Execute != "" { |
| 161 | result = executeCmd(p.Parameter.Execute, projectParams, envVarTranslationMap) |
| 162 | } else if p.Parameter.Type != "" { |
| 163 | err = CustomPromptHandler(p.Parameter.Type, projectParams) |
| 164 | } else if p.Parameter.Value != "" { |
| 165 | result = p.Parameter.Value |
| 166 | } else { |
| 167 | showInfoBox(p.Parameter.Info) |
| 168 | // Move down to the next line to show the prompt |
| 169 | currentLine++ |
| 170 | tm.MoveCursor(1, currentLine) |
| 171 | tm.Flush() // Call it every time at the end of rendering |
| 172 | |
| 173 | err, result = promptParameter(p) |
| 174 | } |
| 175 | if err != nil { |
| 176 | return err |
| 177 | } |
| 178 | |
| 179 | // Append the result to parameter map |
| 180 | projectParams[p.Field] = sanitizeParameterValue(result) |
| 181 | } else { |
| 182 | elseValue := moduleconfig.GetFirstConditionElseValue(p.Parameter) |
| 183 | if elseValue != "" { |
| 184 | flog.Debugf("Skipping prompt(%s) due to condition failed but assigning default value \"%s\"", p.Field, elseValue) |
| 185 | projectParams[p.Field] = elseValue |
| 186 | } else { |
| 187 | flog.Debugf("Skipping prompt(%s) due to condition failed", p.Field) |
| 188 | } |
| 189 | } |
| 190 | return nil |
| 191 | } |
| 192 | |
| 193 | func promptParameter(prompt PromptHandler) (error, string) { |
| 194 | param := prompt.Parameter |