@@ -117,7 +117,7 @@ func (r *resolver) replaceString(ctx context.Context, str string) (interface{},
117117 })
118118}
119119
120- func (r * resolver ) findVariablesInclude (haystack interface {}, include []* regexp.Regexp ) ([]* latest.Variable , error ) {
120+ func (r * resolver ) findVariables (haystack interface {}, skipUnused bool , include []* regexp.Regexp ) ([]* latest.Variable , error ) {
121121 // find out what vars are really used
122122 varsUsed := map [string ]bool {}
123123 switch t := haystack .(type ) {
@@ -144,10 +144,13 @@ func (r *resolver) findVariablesInclude(haystack interface{}, include []*regexp.
144144 }
145145 }
146146
147- // add always resolve variables
148- for _ , v := range r .vars {
149- if v .AlwaysResolve == nil || * v .AlwaysResolve {
150- varsUsed [v .Name ] = true
147+ // add always resolve variables. If skip unused is true, we don't
148+ // resolve by default and instead only resolve the actually found variables
149+ if ! skipUnused {
150+ for _ , v := range r .vars {
151+ if v .AlwaysResolve == nil || * v .AlwaysResolve {
152+ varsUsed [v .Name ] = true
153+ }
151154 }
152155 }
153156
@@ -162,7 +165,7 @@ func (r *resolver) findVariablesInclude(haystack interface{}, include []*regexp.
162165}
163166
164167func (r * resolver ) FindVariables (haystack interface {}) ([]* latest.Variable , error ) {
165- return r .findVariablesInclude (haystack , nil )
168+ return r .findVariables (haystack , false , nil )
166169}
167170
168171func (r * resolver ) getVariableDefinition (name string ) * latest.Variable {
@@ -223,6 +226,7 @@ func (r *resolver) orderVariables(vars map[string]bool) ([]*latest.Variable, err
223226 for i , j := 0 , len (retVars )- 1 ; i < j ; i , j = i + 1 , j - 1 {
224227 retVars [i ], retVars [j ] = retVars [j ], retVars [i ]
225228 }
229+
226230 return retVars , nil
227231}
228232
@@ -257,7 +261,7 @@ func (r *resolver) insertVariableGraph(g *graph.Graph, node *latest.Variable) er
257261 return nil
258262}
259263
260- func (r * resolver ) FillVariablesInclude (ctx context.Context , haystack interface {}, includedPaths []string ) (interface {}, error ) {
264+ func (r * resolver ) FillVariablesInclude (ctx context.Context , haystack interface {}, skipUnused bool , includedPaths []string ) (interface {}, error ) {
261265 paths := []* regexp.Regexp {}
262266 for _ , path := range includedPaths {
263267 path = strings .ReplaceAll (path , "**" , ".+" )
@@ -272,7 +276,7 @@ func (r *resolver) FillVariablesInclude(ctx context.Context, haystack interface{
272276 }
273277
274278 // fill variables
275- preparedConfigInterface , err := r .findAndFillVariables (ctx , haystack , nil , paths )
279+ preparedConfigInterface , err := r .findAndFillVariables (ctx , haystack , skipUnused , nil , paths )
276280 if err != nil {
277281 return nil , err
278282 }
@@ -284,10 +288,10 @@ func (r *resolver) FillVariablesInclude(ctx context.Context, haystack interface{
284288 }
285289
286290 // fill in variables again
287- return r .findAndFillVariables (ctx , preparedConfigInterface , nil , paths )
291+ return r .findAndFillVariables (ctx , preparedConfigInterface , skipUnused , nil , paths )
288292}
289293
290- func (r * resolver ) FillVariablesExclude (ctx context.Context , haystack interface {}, excludedPaths []string ) (interface {}, error ) {
294+ func (r * resolver ) FillVariablesExclude (ctx context.Context , haystack interface {}, skipUnused bool , excludedPaths []string ) (interface {}, error ) {
291295 paths := []* regexp.Regexp {}
292296 for _ , path := range excludedPaths {
293297 path = strings .ReplaceAll (path , "**" , ".+" )
@@ -302,7 +306,7 @@ func (r *resolver) FillVariablesExclude(ctx context.Context, haystack interface{
302306 }
303307
304308 // fill variables
305- preparedConfigInterface , err := r .findAndFillVariables (ctx , haystack , paths , nil )
309+ preparedConfigInterface , err := r .findAndFillVariables (ctx , haystack , skipUnused , paths , nil )
306310 if err != nil {
307311 return nil , err
308312 }
@@ -314,15 +318,15 @@ func (r *resolver) FillVariablesExclude(ctx context.Context, haystack interface{
314318 }
315319
316320 // fill in variables again
317- return r .findAndFillVariables (ctx , preparedConfigInterface , paths , nil )
321+ return r .findAndFillVariables (ctx , preparedConfigInterface , skipUnused , paths , nil )
318322}
319323
320- func (r * resolver ) FillVariables (ctx context.Context , haystack interface {}) (interface {}, error ) {
321- return r .FillVariablesExclude (ctx , haystack , nil )
324+ func (r * resolver ) FillVariables (ctx context.Context , haystack interface {}, skipUnused bool ) (interface {}, error ) {
325+ return r .FillVariablesExclude (ctx , haystack , skipUnused , nil )
322326}
323327
324- func (r * resolver ) findAndFillVariables (ctx context.Context , haystack interface {}, exclude , include []* regexp.Regexp ) (interface {}, error ) {
325- varsUsed , err := r .findVariablesInclude (haystack , include )
328+ func (r * resolver ) findAndFillVariables (ctx context.Context , haystack interface {}, skipUnused bool , exclude , include []* regexp.Regexp ) (interface {}, error ) {
329+ varsUsed , err := r .findVariables (haystack , skipUnused , include )
326330 if err != nil {
327331 return nil , err
328332 }
0 commit comments