github.com/databricks/cli@v0.203.0/bundle/config/variable/variable.go (about) 1 package variable 2 3 import ( 4 "fmt" 5 ) 6 7 const VariableReferencePrefix = "var" 8 9 // An input variable for the bundle config 10 type Variable struct { 11 // A default value which then makes the variable optional 12 Default *string `json:"default,omitempty"` 13 14 // Documentation for this input variable 15 Description string `json:"description,omitempty"` 16 17 // This field stores the resolved value for the variable. The variable are 18 // resolved in the following priority order (from highest to lowest) 19 // 20 // 1. Command line flag. For example: `--var="foo=bar"` 21 // 2. Environment variable. eg: BUNDLE_VAR_foo=bar 22 // 3. Default value as defined in the applicable environments block 23 // 4. Default value defined in variable definition 24 // 5. Throw error, since if no default value is defined, then the variable 25 // is required 26 Value *string `json:"value,omitempty" bundle:"readonly"` 27 } 28 29 // True if the variable has been assigned a default value. Variables without a 30 // a default value are by defination required 31 func (v *Variable) HasDefault() bool { 32 return v.Default != nil 33 } 34 35 // True if variable has already been assigned a value 36 func (v *Variable) HasValue() bool { 37 return v.Value != nil 38 } 39 40 func (v *Variable) Set(val string) error { 41 if v.HasValue() { 42 return fmt.Errorf("variable has already been assigned value: %s", *v.Value) 43 } 44 v.Value = &val 45 return nil 46 }