oh-my-posh/src/segment_terraform.go

36 lines
764 B
Go
Raw Normal View History

2020-10-16 07:25:38 -07:00
package main
type terraform struct {
2021-11-26 01:37:33 -08:00
props properties
2020-10-16 07:25:38 -07:00
env environmentInfo
2021-11-20 02:14:26 -08:00
WorkspaceName string
2020-10-16 07:25:38 -07:00
}
func (tf *terraform) string() string {
2021-11-20 02:14:26 -08:00
segmentTemplate := tf.props.getString(SegmentTemplate, "{{.WorkspaceName}}")
template := &textTemplate{
Template: segmentTemplate,
Context: tf,
Env: tf.env,
}
text, err := template.render()
if err != nil {
return err.Error()
}
return text
2020-10-16 07:25:38 -07:00
}
2021-11-26 01:37:33 -08:00
func (tf *terraform) init(props properties, env environmentInfo) {
2020-10-16 07:25:38 -07:00
tf.props = props
tf.env = env
}
func (tf *terraform) enabled() bool {
cmd := "terraform"
2021-11-20 02:14:26 -08:00
if !tf.env.hasCommand(cmd) || !tf.env.hasFolder(tf.env.getcwd()+"/.terraform") {
2020-10-16 07:25:38 -07:00
return false
}
2021-11-20 02:14:26 -08:00
tf.WorkspaceName, _ = tf.env.runCommand(cmd, "workspace", "show")
2020-10-16 07:25:38 -07:00
return true
}