// Show a prompt to allow the user to interactively insert the data for their Kafka
Show a prompt to allow the user to interactively insert the data for their Kafka
// Show a prompt to allow the user to interactively insert the data for their Kafka
func promptKafkaPayload(opts *options, userQuotaType accountmgmtutil.QuotaSpec) (*kafkamgmtclient.KafkaRequestPayload, error) {
	f := opts.f
	validator := &kafkacmdutil.Validator{
		Localizer:  f.Localizer,
		Connection: f.Connection,
	}
	promptName := &survey.Input{
		Message: f.Localizer.MustLocalize("kafka.create.input.name.message"),
		Help:    f.Localizer.MustLocalize("kafka.create.input.name.help"),
	}
	answers := &promptAnswers{}
	err := survey.AskOne(promptName, &answers.Name, survey.WithValidator(validator.ValidateName), survey.WithValidator(validator.ValidateNameIsAvailable))
	if err != nil {
		return nil, err
	}
	if err != nil {
		return nil, err
	}
	cloudProviderNames, err := GetEnabledCloudProviderNames(opts.f)
	if err != nil {
		return nil, err
	}
	cloudProviderPrompt := &survey.Select{
		Message: f.Localizer.MustLocalize("kafka.create.input.cloudProvider.message"),
		Options: cloudProviderNames,
	}
	err = survey.AskOne(cloudProviderPrompt, &answers.CloudProvider)
	if err != nil {
		return nil, err
	}
	regionIDs, err := GetEnabledCloudRegionIDs(opts.f, answers.CloudProvider, &userQuotaType)
	if err != nil {
		return nil, err
	}
	regionPrompt := &survey.Select{
		Message: f.Localizer.MustLocalize("kafka.create.input.cloudRegion.message"),
		Options: regionIDs,
		Help:    f.Localizer.MustLocalize("kafka.create.input.cloudRegion.help"),
	}
	err = survey.AskOne(regionPrompt, &answers.Region)
	if err != nil {
		return nil, err
	}
	sizes, err := FetchValidKafkaSizes(opts.f, answers.CloudProvider, answers.Region, userQuotaType)
	if err != nil {
		return nil, err
	}
	if len(sizes) == 1 {
		answers.Size = sizes[0].GetId()
	} else {
		sizeLabels := GetValidKafkaSizesLabels(sizes)
		planPrompt := &survey.Select{
			Message: f.Localizer.MustLocalize("kafka.create.input.plan.message"),
			Options: sizeLabels,
		}
		err = survey.AskOne(planPrompt, &answers.Size)
		if err != nil {
			return nil, err
		}
	}
	payload := &kafkamgmtclient.KafkaRequestPayload{
		Name:          answers.Name,
		Region:        &answers.Region,
		CloudProvider: &answers.CloudProvider,
	}
	printSizeWarningIfNeeded(opts.f, answers.Size, sizes)
	payload.SetPlan(mapAmsTypeToBackendType(&userQuotaType) + "." + answers.Size)
	return payload, nil
}
func promptKafkaPayload ( opts * options , userQuotaType accountmgmtutil . QuotaSpec ) ( * kafkamgmtclient . KafkaRequestPayload , error ) { f := opts . f validator := & kafkacmdutil . Validator { Localizer : f . Localizer , Connection : f . Connection , } promptName := & survey . Input { Message : f . Localizer . MustLocalize ( " " ) , Help : f . Localizer . MustLocalize ( " " ) , } answers := & promptAnswers { } err := survey . AskOne ( promptName , & answers . Name , survey . WithValidator ( validator . ValidateName ) , survey . WithValidator ( validator . ValidateNameIsAvailable ) ) if err != nil { return nil , err } if err != nil { return nil , err } cloudProviderNames , err := GetEnabledCloudProviderNames ( opts . f ) if err != nil { return nil , err } cloudProviderPrompt := & survey . Select { Message : f . Localizer . MustLocalize ( " " ) , Options : cloudProviderNames , } err = survey . AskOne ( cloudProviderPrompt , & answers . CloudProvider ) if err != nil { return nil , err } regionIDs , err := GetEnabledCloudRegionIDs ( opts . f , answers . CloudProvider , & userQuotaType ) if err != nil { return nil , err } regionPrompt := & survey . Select { Message : f . Localizer . MustLocalize ( " " ) , Options : regionIDs , Help : f . Localizer . MustLocalize ( " " ) , } err = survey . AskOne ( regionPrompt , & answers . Region ) if err != nil { return nil , err } sizes , err := FetchValidKafkaSizes ( opts . f , answers . CloudProvider , answers . Region , userQuotaType ) if err != nil { return nil , err } if len ( sizes ) == 1 { answers . Size = sizes [ 0 ] . GetId ( ) } else { sizeLabels := GetValidKafkaSizesLabels ( sizes ) planPrompt := & survey . Select { Message : f . Localizer . MustLocalize ( " " ) , Options : sizeLabels , } err = survey . AskOne ( planPrompt , & answers . Size ) if err != nil { return nil , err } } payload := & kafkamgmtclient . KafkaRequestPayload { Name : answers . Name , Region : & answers . Region , CloudProvider : & answers . CloudProvider , } printSizeWarningIfNeeded ( opts . f , answers . Size , sizes ) payload . SetPlan ( mapAmsTypeToBackendType ( & userQuotaType ) + " " + answers . Size ) return payload , nil }
Show a prompt to allow the user to interactively insert the data for their Kafka
Show a prompt to allow the user to interactively insert the data for their Kafka