-
Notifications
You must be signed in to change notification settings - Fork 8
/
services.go
91 lines (76 loc) · 1.83 KB
/
services.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package question
import (
"context"
"fmt"
"strings"
"github.com/AlecAivazis/survey/v2"
"github.com/platformsh/platformify/internal/colors"
"github.com/platformsh/platformify/internal/question/models"
)
type Services struct{}
func (q *Services) Ask(ctx context.Context) error {
answers, ok := models.FromContext(ctx)
if !ok {
return nil
}
if len(answers.Services) != 0 {
// Skip the step
return nil
}
out, _, ok := colors.FromContext(ctx)
if !ok {
return nil
}
fmt.Fprintln(
out,
colors.Colorize(
colors.AccentCode,
"Last but not least, unless you’re creating a static website, your project uses services. Let’s define them:",
),
)
fmt.Fprintln(out)
question := &survey.MultiSelect{
Message: "Select all the services you are using:",
Options: models.ServiceNames.AllTitles(),
}
var services models.ServiceNameList
for {
if err := survey.AskOne(question, &services, survey.WithKeepFilter(true)); err != nil {
return err
}
if len(services) > 0 {
break
}
confirmQuestion := &survey.Confirm{
Message: "You have not selected any service, would you like to proceed anyway?",
Default: false,
}
proceed := false
if err := survey.AskOne(confirmQuestion, &proceed); err != nil {
return err
}
if proceed {
break
}
}
for _, serviceName := range services {
versions, ok := models.ServiceTypeVersions[serviceName]
if !ok || len(versions) == 0 {
return nil
}
service := models.Service{
Name: strings.ReplaceAll(serviceName.String(), "_", "-"),
Type: models.ServiceType{
Name: serviceName.String(),
Version: versions[0],
},
TypeVersions: versions,
}
if serviceName.IsPersistent() {
service.Disk = models.ServiceDisks[0]
service.DiskSizes = models.ServiceDisks
}
answers.Services = append(answers.Services, service)
}
return nil
}