github.com/Racer159/jackal@v0.32.7-0.20240401174413-0bd2339e4f2e/src/pkg/interactive/components.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // SPDX-FileCopyrightText: 2021-Present The Jackal Authors 3 4 // Package interactive contains functions for interacting with the user via STDIN. 5 package interactive 6 7 import ( 8 "fmt" 9 10 "github.com/AlecAivazis/survey/v2" 11 "github.com/Racer159/jackal/src/pkg/message" 12 "github.com/Racer159/jackal/src/pkg/utils" 13 "github.com/Racer159/jackal/src/types" 14 "github.com/pterm/pterm" 15 ) 16 17 // SelectOptionalComponent prompts to confirm optional components 18 func SelectOptionalComponent(component types.JackalComponent) (confirm bool, err error) { 19 message.HorizontalRule() 20 21 displayComponent := component 22 displayComponent.Description = "" 23 utils.ColorPrintYAML(displayComponent, nil, false) 24 if component.Description != "" { 25 message.Question(component.Description) 26 } 27 28 prompt := &survey.Confirm{ 29 Message: fmt.Sprintf("Deploy the %s component?", component.Name), 30 Default: component.Default, 31 } 32 33 return confirm, survey.AskOne(prompt, &confirm) 34 } 35 36 // SelectChoiceGroup prompts to select component groups 37 func SelectChoiceGroup(componentGroup []types.JackalComponent) (types.JackalComponent, error) { 38 message.HorizontalRule() 39 40 var chosen int 41 var options []string 42 43 for _, component := range componentGroup { 44 text := fmt.Sprintf("Name: %s\n Description: %s\n", component.Name, component.Description) 45 options = append(options, text) 46 } 47 48 prompt := &survey.Select{ 49 Message: "Select a component to deploy:", 50 Options: options, 51 } 52 53 pterm.Println() 54 55 return componentGroup[chosen], survey.AskOne(prompt, &chosen) 56 }