From eed043d15d9e7ed6e267f69dd126ff69841f5801 Mon Sep 17 00:00:00 2001 From: Bill Monkman Date: Fri, 12 Jun 2020 16:29:14 -0700 Subject: [PATCH 1/2] Integrate previous changes with new project config struct. This should seet up everything for being able to write the config file. --- go.mod | 1 + internal/context/init.go | 40 ++++++++++++++++++++++++++++------------ 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 6940f00b3..d89cfb6c8 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 // indirect github.com/coreos/go-semver v0.2.0 + github.com/google/go-cmp v0.3.0 github.com/google/uuid v1.1.1 github.com/gorilla/handlers v1.4.2 github.com/gorilla/mux v1.7.3 diff --git a/internal/context/init.go b/internal/context/init.go index 6084848e3..c89f45d6a 100644 --- a/internal/context/init.go +++ b/internal/context/init.go @@ -18,6 +18,7 @@ import ( project "github.com/commitdev/zero/pkg/credentials" "github.com/commitdev/zero/pkg/util/exit" "github.com/commitdev/zero/pkg/util/flog" + "github.com/k0kubun/pp" "github.com/manifoldco/promptui" ) @@ -41,9 +42,13 @@ func Init(outDir string) *projectconfig.ZeroProjectConfig { moduleSources := chooseStack(getRegistry()) moduleConfigs := loadAllModules(moduleSources) - for _ = range moduleConfigs { - // TODO: initialize module structs inside project - } + // Initialize project structs for modules + // for moduleName := range moduleConfigs { + // projectConfig.Modules[moduleName] = Module{ + // Parameters: projectconfig.Parameters{}, + // Files: projectconfig.Files{}, + // } + // } prompts := getProjectPrompts(projectConfig.Name, moduleConfigs) @@ -64,20 +69,31 @@ func Init(outDir string) *projectconfig.ZeroProjectConfig { } projectParameters := promptAllModules(moduleConfigs) - for k, v := range projectParameters { - projectConfig.Parameters[k] = v - // TODO: Add parameters to module structs inside project - } - for moduleName, _ := range moduleConfigs { - // @TODO : Uncomment when this struct is implemented + // initialize stuff + + // Map parameter values back to specific modules + for moduleName, module := range moduleConfigs { repoName := prompts[moduleName].GetParam(initParams) repoURL := fmt.Sprintf("%s/%s", initParams["GithubRootOrg"], repoName) - //projectConfig.Modules[moduleName].Files.Directory = prompts[moduleName].GetParam(initParams) - //projectConfig.Modules[moduleName].Files.Repository = repoURL - fmt.Println(repoURL) + projectModuleParams := make(projectconfig.Parameters) + + // Loop through all the prompted values and find the ones relevant to this module + for parameterKey, parameterValue := range projectParameters { + for _, moduleParameter := range module.Parameters { + if moduleParameter.Field == parameterKey { + projectModuleParams[parameterKey] = parameterValue + } + } + + } + + projectConfig.Modules[moduleName] = projectconfig.NewModule(projectModuleParams, repoName, repoURL) } + // TODO : Write the project config file. For now, print. + pp.Println(projectConfig) + // TODO: load ~/.zero/config.yml (or credentials) // TODO: prompt global credentials From 5456569100d4a07ba40b2604734a3b53157b5116 Mon Sep 17 00:00:00 2001 From: Bill Monkman Date: Fri, 12 Jun 2020 16:31:11 -0700 Subject: [PATCH 2/2] Removed commented blocks --- internal/context/init.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/internal/context/init.go b/internal/context/init.go index c89f45d6a..3f0cdba58 100644 --- a/internal/context/init.go +++ b/internal/context/init.go @@ -42,13 +42,6 @@ func Init(outDir string) *projectconfig.ZeroProjectConfig { moduleSources := chooseStack(getRegistry()) moduleConfigs := loadAllModules(moduleSources) - // Initialize project structs for modules - // for moduleName := range moduleConfigs { - // projectConfig.Modules[moduleName] = Module{ - // Parameters: projectconfig.Parameters{}, - // Files: projectconfig.Files{}, - // } - // } prompts := getProjectPrompts(projectConfig.Name, moduleConfigs) @@ -70,8 +63,6 @@ func Init(outDir string) *projectconfig.ZeroProjectConfig { projectParameters := promptAllModules(moduleConfigs) - // initialize stuff - // Map parameter values back to specific modules for moduleName, module := range moduleConfigs { repoName := prompts[moduleName].GetParam(initParams)