2020-10-09 10:22:32 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
type envvar struct {
|
2021-11-26 01:37:33 -08:00
|
|
|
props properties
|
2021-11-14 01:50:47 -08:00
|
|
|
env environmentInfo
|
|
|
|
Value string
|
2020-10-09 10:22:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
2020-11-12 00:43:32 -08:00
|
|
|
// VarName name of the variable
|
2020-10-09 10:22:32 -07:00
|
|
|
VarName Property = "var_name"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (e *envvar) enabled() bool {
|
|
|
|
name := e.props.getString(VarName, "")
|
2021-11-14 01:50:47 -08:00
|
|
|
e.Value = e.env.getenv(name)
|
|
|
|
return e.Value != ""
|
2020-10-09 10:22:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (e *envvar) string() string {
|
2021-11-15 04:26:36 -08:00
|
|
|
segmentTemplate := e.props.getString(SegmentTemplate, "")
|
|
|
|
if len(segmentTemplate) == 0 {
|
|
|
|
return e.Value
|
|
|
|
}
|
|
|
|
template := &textTemplate{
|
|
|
|
Template: segmentTemplate,
|
|
|
|
Context: e,
|
|
|
|
Env: e.env,
|
|
|
|
}
|
|
|
|
text, err := template.render()
|
|
|
|
if err != nil {
|
|
|
|
return err.Error()
|
|
|
|
}
|
|
|
|
return text
|
2020-10-09 10:22:32 -07:00
|
|
|
}
|
|
|
|
|
2021-11-26 01:37:33 -08:00
|
|
|
func (e *envvar) init(props properties, env environmentInfo) {
|
2020-10-09 10:22:32 -07:00
|
|
|
e.props = props
|
|
|
|
e.env = env
|
|
|
|
}
|