2022-01-26 06:54:36 -08:00
|
|
|
package segments
|
2020-10-16 07:25:38 -07:00
|
|
|
|
2022-01-26 01:23:18 -08:00
|
|
|
import (
|
|
|
|
"oh-my-posh/environment"
|
2022-01-26 04:53:35 -08:00
|
|
|
"oh-my-posh/properties"
|
2022-01-26 01:23:18 -08:00
|
|
|
)
|
|
|
|
|
2022-01-26 05:10:18 -08:00
|
|
|
type Terraform struct {
|
2022-01-26 04:53:35 -08:00
|
|
|
props properties.Properties
|
2022-01-26 01:23:18 -08:00
|
|
|
env environment.Environment
|
|
|
|
|
2021-11-20 02:14:26 -08:00
|
|
|
WorkspaceName string
|
2020-10-16 07:25:38 -07:00
|
|
|
}
|
|
|
|
|
2022-01-26 05:26:56 -08:00
|
|
|
func (tf *Terraform) Template() string {
|
2022-01-23 12:37:51 -08:00
|
|
|
return "{{ .WorkspaceName }}"
|
2020-10-16 07:25:38 -07:00
|
|
|
}
|
|
|
|
|
2022-01-26 05:26:56 -08: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
|
|
|
|
}
|
|
|
|
|
2022-01-26 05:26:56 -08:00
|
|
|
func (tf *Terraform) Enabled() bool {
|
2021-01-05 04:05:37 -08:00
|
|
|
cmd := "terraform"
|
2022-01-23 12:37:51 -08:00
|
|
|
if !tf.env.HasCommand(cmd) || !tf.env.HasFolder(tf.env.Pwd()+"/.terraform") {
|
2020-10-16 07:25:38 -07:00
|
|
|
return false
|
|
|
|
}
|
2022-01-23 12:37:51 -08:00
|
|
|
tf.WorkspaceName, _ = tf.env.RunCommand(cmd, "workspace", "show")
|
2020-10-16 07:25:38 -07:00
|
|
|
return true
|
|
|
|
}
|