Skip to content

Commit

Permalink
Integrate previous changes with new project config struct. This shoul…
Browse files Browse the repository at this point in the history
…d seet up everything for being able to write the config file.
  • Loading branch information
bmonkman committed Jun 12, 2020
1 parent bec2700 commit eed043d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
1 change: 1 addition & 0 deletions go.mod
Expand Up @@ -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
Expand Down
40 changes: 28 additions & 12 deletions internal/context/init.go
Expand Up @@ -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"
)

Expand All @@ -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)

Expand All @@ -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

Expand Down

0 comments on commit eed043d

Please sign in to comment.