@@ -12,8 +12,8 @@ import (
1212 "github.com/AlecAivazis/survey/v2/terminal"
1313 ozzo "github.com/go-ozzo/ozzo-validation"
1414 "github.com/gruntwork-io/boilerplate/internal/color"
15- "github.com/gruntwork-io/boilerplate/internal/logging"
1615 "github.com/gruntwork-io/boilerplate/options"
16+ "github.com/gruntwork-io/boilerplate/pkg/logging"
1717 "github.com/gruntwork-io/boilerplate/render"
1818 "github.com/gruntwork-io/boilerplate/variables"
1919 "github.com/hashicorp/go-multierror"
@@ -24,16 +24,16 @@ const MaxReferenceDepth = 20
2424// GetVariables gets a value for each of the variables specified in boilerplateConfig, other than those already in existingVariables.
2525// The value for a variable can come from the user (if the non-interactive option isn't set), the default value in the
2626// config, or a command line option.
27- func GetVariables (opts * options.BoilerplateOptions , boilerplateConfig , rootBoilerplateConfig * BoilerplateConfig , thisDep * variables.Dependency ) (map [string ]any , error ) {
28- return GetVariablesWithContext (context .Background (), opts , boilerplateConfig , rootBoilerplateConfig , thisDep )
27+ func GetVariables (l logging. Logger , opts * options.BoilerplateOptions , boilerplateConfig , rootBoilerplateConfig * BoilerplateConfig , thisDep * variables.Dependency ) (map [string ]any , error ) {
28+ return GetVariablesWithContext (context .Background (), l , opts , boilerplateConfig , rootBoilerplateConfig , thisDep )
2929}
3030
3131// GetVariablesWithContext collects variables from the user, variable defaults in the boilerplate.yml config, command line options, and environment
3232// variables. Variables in Boilerplate can can be used in both the Boilerplate config itself and in the templates.
3333//
3434// The value for a variable can come from the user (if the non-interactive option isn't set), the default value in the
3535// config, or a command line option.
36- func GetVariablesWithContext (ctx context.Context , opts * options.BoilerplateOptions , boilerplateConfig , rootBoilerplateConfig * BoilerplateConfig , thisDep * variables.Dependency ) (map [string ]any , error ) {
36+ func GetVariablesWithContext (ctx context.Context , l logging. Logger , opts * options.BoilerplateOptions , boilerplateConfig , rootBoilerplateConfig * BoilerplateConfig , thisDep * variables.Dependency ) (map [string ]any , error ) {
3737 renderedVariables := map [string ]any {}
3838
3939 // Add a variable for all variables contained in the root config file. This will allow Golang template users
@@ -104,7 +104,7 @@ func GetVariablesWithContext(ctx context.Context, opts *options.BoilerplateOptio
104104 for _ , keyOrderPair := range keyAndOrderPairs {
105105 variable := variablesInConfig [keyOrderPair .Key ]
106106
107- unmarshalled , err := GetValueForVariable (variable , variablesInConfig , variablesToRender , opts , 0 )
107+ unmarshalled , err := GetValueForVariable (l , variable , variablesInConfig , variablesToRender , opts , 0 )
108108 if err != nil {
109109 return nil , err
110110 }
@@ -114,7 +114,7 @@ func GetVariablesWithContext(ctx context.Context, opts *options.BoilerplateOptio
114114
115115 // Pass all the user provided variables through a rendering pipeline to ensure they are evaluated down to
116116 // primitives.
117- newlyRenderedVariables , err := render .RenderVariablesWithContext (ctx , opts , variablesToRender , renderedVariables )
117+ newlyRenderedVariables , err := render .RenderVariablesWithContext (ctx , l , opts , variablesToRender , renderedVariables )
118118 if err != nil {
119119 return nil , err
120120 }
@@ -135,6 +135,7 @@ func GetVariablesWithContext(ctx context.Context, opts *options.BoilerplateOptio
135135}
136136
137137func GetValueForVariable (
138+ l logging.Logger ,
138139 variable variables.Variable ,
139140 variablesInConfig map [string ]variables.Variable ,
140141 valuesForPreviousVariables map [string ]any ,
@@ -161,11 +162,11 @@ func GetValueForVariable(
161162 return nil , MissingReference {VariableName : variable .Name (), ReferenceName : variable .Reference ()}
162163 }
163164
164- return GetValueForVariable (reference , variablesInConfig , valuesForPreviousVariables , opts , referenceDepth + 1 )
165+ return GetValueForVariable (l , reference , variablesInConfig , valuesForPreviousVariables , opts , referenceDepth + 1 )
165166 }
166167
167168 // Run the value we receive from getVariable through validations, ensuring values provided by --var-files will also be checked
168- value , err := getVariable (variable , opts )
169+ value , err := getVariable (l , variable , opts )
169170 if err != nil {
170171 return value , err
171172 }
@@ -183,23 +184,23 @@ func GetValueForVariable(
183184
184185// Get a value for the given variable. The value can come from the user (if the non-interactive option isn't set), the
185186// default value in the config, or a command line option.
186- func getVariable (variable variables.Variable , opts * options.BoilerplateOptions ) (any , error ) {
187+ func getVariable (l logging. Logger , variable variables.Variable , opts * options.BoilerplateOptions ) (any , error ) {
187188 valueFromVars , valueSpecifiedInVars := getVariableFromVars (variable , opts )
188189
189190 switch {
190191 case valueSpecifiedInVars :
191- logging . Logger . Printf ("Using value specified via command line options for variable '%s': %s" , variable .FullName (), valueFromVars )
192+ l . Debugf ("Using value specified via command line options for variable '%s': %s" , variable .FullName (), valueFromVars )
192193 return valueFromVars , nil
193194 case opts .NonInteractive && variable .Default () != nil :
194- logging . Logger . Printf ("Using default value for variable '%s': %v" , variable .FullName (), variable .Default ())
195+ l . Debugf ("Using default value for variable '%s': %v" , variable .FullName (), variable .Default ())
195196 return variable .Default (), nil
196197 case opts .NonInteractive :
197198 return nil , MissingVariableWithNonInteractiveMode (variable .FullName ())
198199 case variable .Default () != nil && ! variable .Confirm ():
199- logging . Logger . Printf ("Using default value for variable '%s': %v" , variable .FullName (), variable .Default ())
200+ l . Debugf ("Using default value for variable '%s': %v" , variable .FullName (), variable .Default ())
200201 return variable .Default (), nil
201202 default :
202- return getVariableFromUser (variable , variables.InvalidEntries {})
203+ return getVariableFromUser (l , variable , variables.InvalidEntries {})
203204 }
204205}
205206
@@ -215,7 +216,7 @@ func getVariableFromVars(variable variables.Variable, opts *options.BoilerplateO
215216}
216217
217218// Get the value for the given variable by prompting the user
218- func getVariableFromUser (variable variables.Variable , invalidEntries variables.InvalidEntries ) (any , error ) {
219+ func getVariableFromUser (l logging. Logger , variable variables.Variable , invalidEntries variables.InvalidEntries ) (any , error ) {
219220 // Add a newline for legibility and padding
220221 fmt .Println ()
221222
@@ -242,12 +243,12 @@ func getVariableFromUser(variable variables.Variable, invalidEntries variables.I
242243 },
243244 }
244245
245- return getVariableFromUser (variable , ie )
246+ return getVariableFromUser (l , variable , ie )
246247 }
247248
248249 if value == "" {
249250 // TODO: what if the user wanted an empty string instead of the default?
250- logging . Logger . Printf ("Using default value for variable '%s': %v" , variable .FullName (), variable .Default ())
251+ l . Debugf ("Using default value for variable '%s': %v" , variable .FullName (), variable .Default ())
251252 return variable .Default (), nil
252253 }
253254
0 commit comments