MCPcopy Index your code
hub / github.com/commitdev/zero / PromptModuleParams

Function PromptModuleParams

internal/init/prompts.go:259–299  ·  view source on GitHub ↗

PromptModuleParams renders series of prompt UI based on the config

(moduleConfig moduleconfig.ModuleConfig, parameters map[string]string)

Source from the content-addressed store, hash-verified

257
258// PromptModuleParams renders series of prompt UI based on the config
259func PromptModuleParams(moduleConfig moduleconfig.ModuleConfig, parameters map[string]string) (map[string]string, error) {
260 envVarTranslationMap := moduleConfig.GetParamEnvVarTranslationMap()
261 for _, parameter := range moduleConfig.Parameters {
262 // deduplicate fields already prompted and received
263 if _, isAlreadySet := parameters[parameter.Field]; isAlreadySet {
264 continue
265 }
266
267 var validateFunc func(input string) error = nil
268
269 // type:regex field validation for zero-module.yaml
270 if parameter.FieldValidation.Type == constants.RegexValidation {
271 validateFunc = func(input string) error {
272 var regexRule = regexp.MustCompile(parameter.FieldValidation.Value)
273 if !regexRule.MatchString(input) {
274 return errors.New(parameter.FieldValidation.ErrorMessage)
275 }
276 return nil
277 }
278 }
279 // TODO: type:fuction field validation for zero-module.yaml
280
281 promptHandler := PromptHandler{
282 Parameter: parameter,
283 Condition: paramConditionsMapper(parameter.Conditions),
284 Validate: validateFunc,
285 }
286 // merging the context of param and credentals
287 // this treats credentialEnvs as throwaway, parameters is shared between modules
288 // so credentials should not be in parameters as it gets returned to parent
289 // for k, v := range parameters {
290 // credentialEnvs[k] = v
291 // }
292 err := promptHandler.RunPrompt(parameters, envVarTranslationMap)
293 if err != nil {
294 return parameters, err
295 }
296 }
297 flog.Debugf("Module %s prompt: \n %#v", moduleConfig.Name, parameters)
298 return parameters, nil
299}
300
301// promptAllModules takes a map of all the modules and prompts the user for values for all the parameters
302// Important: This is done here because in this step we share the parameter across modules,

Callers 1

promptAllModulesFunction · 0.85

Calls 4

RunPromptMethod · 0.95
DebugfFunction · 0.92
paramConditionsMapperFunction · 0.85

Tested by

no test coverage detected