@@ -24,7 +24,8 @@ type Registry map[string][]string
2424// Create cloud provider context
2525func Init (outDir string ) * projectconfig.ZeroProjectConfig {
2626 projectConfig := defaultProjConfig ()
27- projectConfig .Name = promptProjectName ()
27+
28+ projectConfig .Name = getProjectNamePrompt ().GetParam (projectConfig .Parameters )
2829
2930 rootDir := path .Join (outDir , projectConfig .Name )
3031 flog .Infof (":tada: Creating project" )
@@ -36,15 +37,17 @@ func Init(outDir string) *projectconfig.ZeroProjectConfig {
3637 exit .Fatal ("Error creating root: %v " , err )
3738 }
3839
39- projectConfig .Context ["ShouldPushRepoUpstream" ] = promptPushRepoUpstream ()
40- projectConfig .Context ["GithubRootOrg" ] = promptGithubRootOrg ()
41- projectConfig .Context ["githubPersonalToken" ] = promptGithubPersonalToken (projectConfig .Name )
42-
43- // chooseCloudProvider(&projectConfig)
44- // fmt.Println(&projectConfig)
45- // s := project.GetSecrets(rootDir)
46- // fillProviderDetails(&projectConfig, s)
47- // fmt.Println(&projectConfig)
40+ prompts := getProjectPrompts (projectConfig .Name )
41+ projectConfig .Parameters ["ShouldPushRepoUpstream" ] = prompts ["ShouldPushRepoUpstream" ].GetParam (projectConfig .Parameters )
42+ // Prompting for push-up stream, then conditionally prompting for github
43+ projectConfig .Parameters ["GithubRootOrg" ] = prompts ["GithubRootOrg" ].GetParam (projectConfig .Parameters )
44+ personalToken := prompts ["githubPersonalToken" ].GetParam (projectConfig .Parameters )
45+ if personalToken != "" && personalToken != globalconfig .GetUserCredentials (projectConfig .Name ).AccessToken {
46+ projectConfig .Parameters ["githubPersonalToken" ] = personalToken
47+ projectCredential := globalconfig .GetUserCredentials (projectConfig .Name )
48+ projectCredential .GithubResourceConfig .AccessToken = personalToken
49+ globalconfig .Save (projectCredential )
50+ }
4851 moduleSources := chooseStack (getRegistry ())
4952 moduleConfigs := loadAllModules (moduleSources )
5053 for _ = range moduleConfigs {
@@ -53,7 +56,7 @@ func Init(outDir string) *projectconfig.ZeroProjectConfig {
5356
5457 projectParameters := promptAllModules (moduleConfigs )
5558 for k , v := range projectParameters {
56- projectConfig .Context [k ] = v
59+ projectConfig .Parameters [k ] = v
5760 // TODO: Add parameters to module structs inside project
5861 }
5962
@@ -82,77 +85,54 @@ func promptAllModules(modules map[string]moduleconfig.ModuleConfig) map[string]s
8285 parameterValues := make (map [string ]string )
8386 for _ , config := range modules {
8487 var err error
85- parameterValues , err = module . PromptParams (config , parameterValues )
88+ parameterValues , err = PromptModuleParams (config , parameterValues )
8689 if err != nil {
8790 exit .Fatal ("Exiting prompt: %v\n " , err )
8891 }
8992 }
9093 return parameterValues
9194}
9295
93- // global configs
94- func promptPushRepoUpstream () string {
95- providerPrompt := promptui.Prompt {
96- Label : "Should the created projects be checked into github automatically? (y/n)" ,
97- Default : "y" ,
98- AllowEdit : false ,
99- }
100- providerResult , err := providerPrompt .Run ()
101- if err != nil {
102- exit .Fatal ("Exiting prompt: %v\n " , err )
103- }
104- return providerResult
105- }
106-
107- func promptGithubRootOrg () string {
108- providerPrompt := promptui.Prompt {
109- Label : "What's the root of the github org to create repositories in?" ,
110- Default : "github.com/" ,
111- AllowEdit : true ,
112- }
113- result , err := providerPrompt .Run ()
114- if err != nil {
115- exit .Fatal ("Exiting prompt: %v\n " , err )
116- }
117- return result
118- }
119-
120- func promptGithubPersonalToken (projectName string ) string {
121- defaultToken := ""
122-
123- project := globalconfig .GetUserCredentials (projectName )
124- if project .GithubResourceConfig .AccessToken != "" {
125- defaultToken = project .GithubResourceConfig .AccessToken
126- }
127-
128- providerPrompt := promptui.Prompt {
129- Label : "Github Personal Access Token with access to the above organization" ,
130- Default : defaultToken ,
131- }
132- result , err := providerPrompt .Run ()
133- if err != nil {
134- exit .Fatal ("Prompt failed %v\n " , err )
135- }
136-
137- // If its different from saved token, update it
138- if project .GithubResourceConfig .AccessToken != result {
139- project .GithubResourceConfig .AccessToken = result
140- globalconfig .Save (project )
96+ // Project name is prompt individually because the rest of the prompts
97+ // requires the projectName to populate defaults
98+ func getProjectNamePrompt () PromptHandler {
99+ return PromptHandler {
100+ moduleconfig.Parameter {
101+ Field : "projectName" ,
102+ Label : "Project Name" ,
103+ Default : "" ,
104+ },
105+ NoCondition ,
141106 }
142- return result
143107}
144108
145- func promptProjectName () string {
146- providerPrompt := promptui.Prompt {
147- Label : "Project Name" ,
148- Default : "" ,
149- AllowEdit : false ,
150- }
151- result , err := providerPrompt .Run ()
152- if err != nil {
153- exit .Fatal ("Prompt failed %v\n " , err )
109+ func getProjectPrompts (projectName string ) map [string ]PromptHandler {
110+ return map [string ]PromptHandler {
111+ "ShouldPushRepoUpstream" : {
112+ moduleconfig.Parameter {
113+ Field : "ShouldPushRepoUpstream" ,
114+ Label : "Should the created projects be checked into github automatically? (y/n)" ,
115+ Default : "y" ,
116+ },
117+ NoCondition ,
118+ },
119+ "GithubRootOrg" : {
120+ moduleconfig.Parameter {
121+ Field : "GithubRootOrg" ,
122+ Label : "What's the root of the github org to create repositories in?" ,
123+ Default : "github.com/" ,
124+ },
125+ KeyMatchCondition ("ShouldPushRepoUpstream" , "y" ),
126+ },
127+ "githubPersonalToken" : {
128+ moduleconfig.Parameter {
129+ Field : "githubPersonalToken" ,
130+ Label : "Github Personal Access Token with access to the above organization" ,
131+ Default : globalconfig .GetUserCredentials (projectName ).AccessToken ,
132+ },
133+ KeyMatchCondition ("ShouldPushRepoUpstream" , "y" ),
134+ },
154135 }
155- return result
156136}
157137
158138func chooseCloudProvider (projectConfig * projectconfig.ZeroProjectConfig ) {
@@ -241,7 +221,7 @@ func defaultProjConfig() projectconfig.ZeroProjectConfig {
241221 Infrastructure : projectconfig.Infrastructure {
242222 AWS : nil ,
243223 },
244- Context : map [string ]string {},
245- Modules : []string {},
224+ Parameters : map [string ]string {},
225+ Modules : []string {},
246226 }
247227}
0 commit comments