oh-my-posh/src/segment_terraform.go

32 lines
620 B
Go
Raw Normal View History

2020-10-16 07:25:38 -07:00
package main
import (
"oh-my-posh/environment"
"oh-my-posh/properties"
)
2022-01-26 05:10:18 -08:00
type Terraform struct {
props properties.Properties
env environment.Environment
2021-11-20 02:14:26 -08:00
WorkspaceName string
2020-10-16 07:25:38 -07:00
}
func (tf *Terraform) Template() string {
return "{{ .WorkspaceName }}"
2020-10-16 07:25:38 -07:00
}
func (tf *Terraform) Init(props properties.Properties, env environment.Environment) {
2020-10-16 07:25:38 -07:00
tf.props = props
tf.env = env
}
func (tf *Terraform) Enabled() bool {
cmd := "terraform"
if !tf.env.HasCommand(cmd) || !tf.env.HasFolder(tf.env.Pwd()+"/.terraform") {
2020-10-16 07:25:38 -07:00
return false
}
tf.WorkspaceName, _ = tf.env.RunCommand(cmd, "workspace", "show")
2020-10-16 07:25:38 -07:00
return true
}