11package context
22
33import (
4+ "fmt"
45 "os"
56 "path"
7+ "sync"
68
79 "github.com/aws/aws-sdk-go/aws"
810 "github.com/aws/aws-sdk-go/aws/awserr"
@@ -37,7 +39,14 @@ func Init(outDir string) *projectconfig.ZeroProjectConfig {
3739 exit .Fatal ("Error creating root: %v " , err )
3840 }
3941
40- prompts := getProjectPrompts (projectConfig .Name )
42+ moduleSources := chooseStack (getRegistry ())
43+ moduleConfigs := loadAllModules (moduleSources )
44+ for _ = range moduleConfigs {
45+ // TODO: initialize module structs inside project
46+ }
47+
48+ prompts := getProjectPrompts (projectConfig .Name , moduleConfigs )
49+
4150 projectConfig .Parameters ["ShouldPushRepoUpstream" ] = prompts ["ShouldPushRepoUpstream" ].GetParam (projectConfig .Parameters )
4251 // Prompting for push-up stream, then conditionally prompting for github
4352 projectConfig .Parameters ["GithubRootOrg" ] = prompts ["GithubRootOrg" ].GetParam (projectConfig .Parameters )
@@ -48,18 +57,19 @@ func Init(outDir string) *projectconfig.ZeroProjectConfig {
4857 projectCredential .GithubResourceConfig .AccessToken = personalToken
4958 globalconfig .Save (projectCredential )
5059 }
51- moduleSources := chooseStack (getRegistry ())
52- moduleConfigs := loadAllModules (moduleSources )
53- for _ = range moduleConfigs {
54- // TODO: initialize module structs inside project
55- }
5660
5761 projectParameters := promptAllModules (moduleConfigs )
5862 for k , v := range projectParameters {
5963 projectConfig .Parameters [k ] = v
6064 // TODO: Add parameters to module structs inside project
6165 }
6266
67+ for moduleName , _ := range moduleConfigs {
68+ // @TODO : Uncomment when this struct is implemented
69+ //projectConfig.Modules[moduleName].Files.Directory = prompts[moduleName].GetParam(projectConfig.Parameters))
70+ fmt .Println (prompts [moduleName ].GetParam (projectConfig .Parameters ))
71+ }
72+
6373 // TODO: load ~/.zero/config.yml (or credentials)
6474 // TODO: prompt global credentials
6575
@@ -70,8 +80,15 @@ func Init(outDir string) *projectconfig.ZeroProjectConfig {
7080func loadAllModules (moduleSources []string ) map [string ]moduleconfig.ModuleConfig {
7181 modules := make (map [string ]moduleconfig.ModuleConfig )
7282
83+ wg := sync.WaitGroup {}
84+ wg .Add (len (moduleSources ))
85+ for _ , moduleSource := range moduleSources {
86+ go module .FetchModule (moduleSource , & wg )
87+ }
88+ wg .Wait ()
89+
7390 for _ , moduleSource := range moduleSources {
74- mod , err := module .FetchModule (moduleSource )
91+ mod , err := module .ParseModuleConfig (moduleSource )
7592 if err != nil {
7693 exit .Fatal ("Unable to load module: %v\n " , err )
7794 }
@@ -106,8 +123,8 @@ func getProjectNamePrompt() PromptHandler {
106123 }
107124}
108125
109- func getProjectPrompts (projectName string ) map [string ]PromptHandler {
110- return map [string ]PromptHandler {
126+ func getProjectPrompts (projectName string , modules map [ string ]moduleconfig. ModuleConfig ) map [string ]PromptHandler {
127+ handlers := map [string ]PromptHandler {
111128 "ShouldPushRepoUpstream" : {
112129 moduleconfig.Parameter {
113130 Field : "ShouldPushRepoUpstream" ,
@@ -133,6 +150,21 @@ func getProjectPrompts(projectName string) map[string]PromptHandler {
133150 KeyMatchCondition ("ShouldPushRepoUpstream" , "y" ),
134151 },
135152 }
153+
154+ for moduleName , module := range modules {
155+ label := fmt .Sprintf ("What do you want to call the %s project?" , moduleName )
156+
157+ handlers [moduleName ] = PromptHandler {
158+ moduleconfig.Parameter {
159+ Field : moduleName ,
160+ Label : label ,
161+ Default : module .OutputDir ,
162+ },
163+ NoCondition ,
164+ }
165+ }
166+
167+ return handlers
136168}
137169
138170func chooseCloudProvider (projectConfig * projectconfig.ZeroProjectConfig ) {
0 commit comments