diff --git a/internal/init/init.go b/internal/init/init.go index d92f0aa7..a0ddfc11 100644 --- a/internal/init/init.go +++ b/internal/init/init.go @@ -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 { diff --git a/internal/init/prompts.go b/internal/init/prompts.go index ac40b248..f060f968 100644 --- a/internal/init/prompts.go +++ b/internal/init/prompts.go @@ -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" @@ -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 @@ -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