Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: missing projectName context in prompt:execute #410

Merged
merged 1 commit into from
Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func Init(outDir string, localModulePath string) *projectconfig.ZeroProjectConfi
// Prompting for push-up stream, then conditionally prompting for github
prompts["GithubRootOrg"].RunPrompt(initParams, emptyEnvVarTranslationMap)

projectData := promptAllModules(moduleConfigs)
projectData := promptAllModules(moduleConfigs, &projectConfig)

// Map parameter values back to specific modules
for moduleName, module := range moduleConfigs {
Expand Down
12 changes: 10 additions & 2 deletions internal/init/prompts.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

tm "github.com/buger/goterm"
"github.com/commitdev/zero/internal/config/moduleconfig"
"github.com/commitdev/zero/internal/config/projectconfig"
"github.com/commitdev/zero/internal/constants"
"github.com/commitdev/zero/internal/util"
"github.com/commitdev/zero/pkg/util/exit"
Expand Down Expand Up @@ -276,8 +277,8 @@ func PromptModuleParams(moduleConfig moduleconfig.ModuleConfig, parameters map[s
// promptAllModules takes a map of all the modules and prompts the user for values for all the parameters
// Important: This is done here because in this step we share the parameter across modules,
// meaning if module A and B both asks for region, it will reuse the response for both (and is deduped during runtime)
func promptAllModules(modules map[string]moduleconfig.ModuleConfig) map[string]string {
parameterValues := map[string]string{}
func promptAllModules(modules map[string]moduleconfig.ModuleConfig, projectConfig *projectconfig.ZeroProjectConfig) map[string]string {
parameterValues := availableProjectContext(projectConfig)
for _, config := range modules {
var err error

Expand All @@ -289,6 +290,13 @@ func promptAllModules(modules map[string]moduleconfig.ModuleConfig) map[string]s
return parameterValues
}

// availableProjectContext declares a list of variables usable in modules parameter prompt's execute step
func availableProjectContext(projectConfig *projectconfig.ZeroProjectConfig) map[string]string {
return map[string]string{
"projectName": projectConfig.Name,
}
}

func paramConditionsMapper(conditions []moduleconfig.Condition) CustomConditionSignature {
if len(conditions) == 0 {
return NoCondition
Expand Down