/
questions.go
93 lines (79 loc) · 3.11 KB
/
questions.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
92
93
package cmd
func environmentQuestions(projectName string, environmentConfig map[string]EnvironmentData, environments []string) []string {
choosenEnvironment := prompt("Environment")
awsAccountId := requiredPrompt("AWSAccountID")
environmentData := EnvironmentData {
AwsAccountId: awsAccountId,
}
environmentConfig[choosenEnvironment] = environmentData
environments = append(environments, choosenEnvironment)
addAnotherEnvironment := yesNo("Would you like to add another environment (recommended if your AWS account ID differs per environment)")
if addAnotherEnvironment {
return environmentQuestions(projectName, environmentConfig, environments)
}
return environments
}
func Questions(projectName string) (WebsocketConfig, map[string]EnvironmentData) {
choosenLanguage := language()
infrastructureDestinationFilePath := prompt("InfrastructureFilePath")
websocketDestinationFilePath := prompt("WebsocketFilePath")
AwsRegion := prompt("AwsRegion")
authorizationKey := prompt("AuthorizationKey")
var environments []string
environmentConfig := make(map[string]EnvironmentData)
choosenEnvironments := environmentQuestions(projectName, environmentConfig, environments)
existingEnvironments := make(map[string]bool)
var uniqueEnvironments []string
for _, environment := range choosenEnvironments {
_, environmentAlreadyExists := existingEnvironments[environment]
if !environmentAlreadyExists {
existingEnvironments[environment] = true
uniqueEnvironments = append(uniqueEnvironments, environment)
}
}
websocketConfig := WebsocketConfig {
Environments: uniqueEnvironments,
ProjectName: projectName,
Language: choosenLanguage,
InfrastructureFilePath: infrastructureDestinationFilePath,
WebsocketFilePath: websocketDestinationFilePath,
AwsRegion: AwsRegion,
AuthorizationKey: authorizationKey,
}
return websocketConfig, environmentConfig
}
func GetQuestionDetails(reference string) QuestionDetails {
QuestionsConfig := map[string]QuestionDetails{
"InfrastructureFilePath": {
QuestionLabel: "Infrastructure Code Location Path. Default value is <current-directory>/infrastructure",
DefaultResponse: "/infrastructure",
ResponseLabel: "Your Infrastructure Code Location Path:",
},
"WebsocketFilePath": {
QuestionLabel: "WebSocket Code Location Path. Default value is <current-directory>/websocket",
DefaultResponse: "/api/websocket",
ResponseLabel: "Your WebSocket Code Location Path:",
},
"AwsRegion": {
QuestionLabel: "AWS Region. Default value is eu-west-2",
DefaultResponse: "eu-west-2",
ResponseLabel: "Your AWS Region:",
},
"AuthorizationKey": {
QuestionLabel: "Authorization Key Name. Default value is authorization",
DefaultResponse: "Authorization",
ResponseLabel: "Your Authorization Query Parameter Key is:",
},
"Environment": {
QuestionLabel: "Environment Name. Default value is development",
DefaultResponse: "development",
ResponseLabel: "Environment Choosen:",
},
"AWSAccountID": {
QuestionLabel: "AWS Account ID",
DefaultResponse: "",
ResponseLabel: "Your AWS Account ID:",
},
}
return QuestionsConfig[reference]
}