github.com/terramate-io/tf@v0.0.0-20230830114523-fce866b4dfcd/command/meta_new.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: MPL-2.0 3 4 package command 5 6 import ( 7 "os" 8 "strconv" 9 10 "github.com/terramate-io/tf/plans/planfile" 11 ) 12 13 // NOTE: Temporary file until this branch is cleaned up. 14 15 // Input returns whether or not input asking is enabled. 16 func (m *Meta) Input() bool { 17 if test || !m.input { 18 return false 19 } 20 21 if envVar := os.Getenv(InputModeEnvVar); envVar != "" { 22 if v, err := strconv.ParseBool(envVar); err == nil && !v { 23 return false 24 } 25 } 26 27 return true 28 } 29 30 // PlanFile loads the plan file at the given path, which might be either a local 31 // or cloud plan. 32 // 33 // If the return value and error are both nil, the given path exists but seems 34 // to be a configuration directory instead. 35 // 36 // Error will be non-nil if path refers to something which looks like a plan 37 // file and loading the file fails. 38 func (m *Meta) PlanFile(path string) (*planfile.WrappedPlanFile, error) { 39 fi, err := os.Stat(path) 40 if err != nil { 41 return nil, err 42 } 43 44 if fi.IsDir() { 45 // Looks like a configuration directory. 46 return nil, nil 47 } 48 49 return planfile.OpenWrapped(path) 50 }