@@ -15,11 +15,11 @@ import (
1515 "github.com/commitdev/zero/pkg/util/exit"
1616 "github.com/commitdev/zero/pkg/util/flog"
1717 "github.com/manifoldco/promptui"
18+ "gopkg.in/yaml.v2"
1819)
1920
20- // Constant to maintain prompt orders so users can have the same flow,
21- // modules get downloaded asynchronously therefore its easier to just hardcode an order
22- var AvailableVendorOrders = []string {"aws" , "github" , "circleci" }
21+ const cyanArrow = "\033 [36m\U000025B6 \033 [0m"
22+ const greenCheckMark = "\033 [32m\U00002714 \033 [0m"
2323
2424const awsPickProfile = "Existing AWS Profiles"
2525const awsManualInputCredentials = "Enter my own AWS credentials"
@@ -152,12 +152,24 @@ func promptParameter(prompt PromptHandler) (error, string) {
152152 var err error
153153 var result string
154154 if len (param .Options ) > 0 {
155+ var selectedIndex int
156+ // Scope of selected does not have the label data, so we need a dynamic
157+ // template with string format to put in the label in `selected`
158+ optionTemplate := & promptui.SelectTemplates {
159+ Label : `{{ . }}` ,
160+ Active : fmt .Sprintf ("%s {{ .Value | cyan }}" , cyanArrow ),
161+ Inactive : " {{ .Value }}" ,
162+ Selected : fmt .Sprintf ("%s %s: {{ .Value }}" , greenCheckMark , label ),
163+ }
164+
155165 prompt := promptui.Select {
156- Label : label ,
157- Items : param .Options ,
166+ Label : label ,
167+ Items : param .Options ,
168+ Templates : optionTemplate ,
158169 }
159- _ , result , err = prompt .Run ()
160170
171+ selectedIndex , _ , err = prompt .Run ()
172+ result = param .Options [selectedIndex ].Key .(string )
161173 } else {
162174 prompt := promptui.Prompt {
163175 Label : label ,
@@ -168,7 +180,7 @@ func promptParameter(prompt PromptHandler) (error, string) {
168180 result , err = prompt .Run ()
169181 }
170182 if err != nil {
171- exit . Fatal ( "Exiting prompt: %v \n " , err )
183+ return err , ""
172184 }
173185
174186 return nil , result
@@ -287,3 +299,14 @@ func appendToSet(set []string, toAppend []string) []string {
287299 }
288300 return set
289301}
302+
303+ func listToPromptOptions (list []string ) yaml.MapSlice {
304+ mapSlice := make (yaml.MapSlice , len (list ))
305+ for i := 0 ; i < len (list ); i ++ {
306+ mapSlice [i ] = yaml.MapItem {
307+ Key : list [i ],
308+ Value : list [i ],
309+ }
310+ }
311+ return mapSlice
312+ }
0 commit comments