opentofu/internal/command/meta_new.go

47 lines
1000 B
Go
Raw Normal View History

2017-01-18 22:50:45 -06:00
package command
import (
"os"
"strconv"
"github.com/hashicorp/terraform/internal/plans/planfile"
2017-01-18 22:50:45 -06:00
)
// NOTE: Temporary file until this branch is cleaned up.
// Input returns whether or not input asking is enabled.
func (m *Meta) Input() bool {
if test || !m.input {
return false
}
if envVar := os.Getenv(InputModeEnvVar); envVar != "" {
if v, err := strconv.ParseBool(envVar); err == nil && !v {
return false
}
}
return true
}
// PlanFile returns a reader for the plan file at the given path.
2017-01-18 22:50:45 -06:00
//
// If the return value and error are both nil, the given path exists but seems
// to be a configuration directory instead.
2017-01-18 22:50:45 -06:00
//
// Error will be non-nil if path refers to something which looks like a plan
// file and loading the file fails.
func (m *Meta) PlanFile(path string) (*planfile.Reader, error) {
fi, err := os.Stat(path)
2017-01-18 22:50:45 -06:00
if err != nil {
return nil, err
2017-01-18 22:50:45 -06:00
}
if fi.IsDir() {
// Looks like a configuration directory.
2017-01-18 22:50:45 -06:00
return nil, nil
}
return planfile.Open(path)
2017-01-18 22:50:45 -06:00
}