Extend composed consumer with request validation
This commit is contained in:
@@ -141,6 +141,31 @@ func selectedCampaign(configuration appConfiguration, supplied commandkit.Suppli
|
||||
return name, chosen, nil
|
||||
}
|
||||
|
||||
func buildValidationRequest(ctx context.Context, seed ckprompt.ValidationRequest, input *inspectionInput, cache *runCache) (promptkit.RunRequest, error) {
|
||||
application, err := loadApplicationConfig(ctx, seed.Selection, input, cache)
|
||||
if err != nil {
|
||||
return promptkit.RunRequest{}, err
|
||||
}
|
||||
name, _, err := selectedCampaign(application.Config, input.Campaign)
|
||||
if err != nil {
|
||||
return promptkit.RunRequest{}, err
|
||||
}
|
||||
|
||||
request := seed.Request
|
||||
vars := make(map[string]string, len(request.Vars)+2)
|
||||
for key, value := range request.Vars {
|
||||
vars[key] = value
|
||||
}
|
||||
if _, supplied := vars["topic"]; !supplied {
|
||||
vars["topic"] = name + " campaign planning"
|
||||
}
|
||||
if _, supplied := vars["mode"]; !supplied {
|
||||
vars["mode"] = ""
|
||||
}
|
||||
request.Vars = vars
|
||||
return request, nil
|
||||
}
|
||||
|
||||
func newApp() (*commandkit.App, error) {
|
||||
limitDefault := 0
|
||||
limitFlag := commandkit.ValueFlag(commandkit.FlagMeta{Name: "limit", Usage: "Override the application item limit."}, &limitDefault, strconv.Atoi,
|
||||
@@ -170,6 +195,7 @@ func newApp() (*commandkit.App, error) {
|
||||
definitions.NewInput = inputFactory
|
||||
definitions.NewState = stateFactory
|
||||
definitions.Selectors = []commandkit.Flag[*inspectionInput]{campaignSelector()}
|
||||
definitions = ckprompt.WithRequestValidation(definitions, loadPromptEngine, buildValidationRequest)
|
||||
definitionCommand := ckprompt.Command(definitions)
|
||||
|
||||
store := map[string]session{
|
||||
|
||||
Reference in New Issue
Block a user