MCPcopy Index your code
hub / github.com/devspace-sh/devspace / fillVariable

Method fillVariable

pkg/devspace/config/loader/variable/resolver.go:558–585  ·  view source on GitHub ↗
(ctx context.Context, name string, definition *latest.Variable)

Source from the content-addressed store, hash-verified

556}
557
558func (r *resolver) fillVariable(ctx context.Context, name string, definition *latest.Variable) (interface{}, error) {
559 // is runtime variable
560 if strings.HasPrefix(name, "runtime.") {
561 return nil, fmt.Errorf("cannot resolve %s in this config area as this config region is loaded on startup. You can only use runtime variables in the following locations: \n %s", name, strings.Join(runtime.Locations, "\n "))
562 }
563
564 // fill variable without definition
565 if definition == nil {
566 return NewUndefinedVariable(name, r.localCache, r.log).Load(ctx, definition)
567 }
568
569 // trim space from variable definition
570 definition.Name = strings.TrimSpace(definition.Name)
571
572 // fill variable by source
573 switch definition.Source {
574 case latest.VariableSourceEnv:
575 return NewEnvVariable(name).Load(ctx, definition)
576 case latest.VariableSourceDefault, latest.VariableSourceInput, latest.VariableSourceAll:
577 return NewDefaultVariable(name, filepath.Dir(r.options.ConfigPath), r.localCache, r.log).Load(ctx, definition)
578 case latest.VariableSourceNone:
579 return NewNoneVariable(name).Load(ctx, definition)
580 case latest.VariableSourceCommand:
581 return NewCommandVariable(name, filepath.Dir(r.options.ConfigPath)).Load(ctx, definition)
582 default:
583 return nil, errors.Errorf("unrecognized variable source '%s', please choose one of 'all', 'input', 'env' or 'none'", name)
584 }
585}

Callers 1

resolveMethod · 0.95

Calls 7

NewUndefinedVariableFunction · 0.85
NewEnvVariableFunction · 0.85
NewDefaultVariableFunction · 0.85
NewNoneVariableFunction · 0.85
NewCommandVariableFunction · 0.85
LoadMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected