github.com/chanzuckerberg/terraform@v0.11.12-beta1/tfdiags/source_range.go (about) 1 package tfdiags 2 3 import ( 4 "fmt" 5 "os" 6 "path/filepath" 7 ) 8 9 type SourceRange struct { 10 Filename string 11 Start, End SourcePos 12 } 13 14 type SourcePos struct { 15 Line, Column, Byte int 16 } 17 18 // StartString returns a string representation of the start of the range, 19 // including the filename and the line and column numbers. 20 func (r SourceRange) StartString() string { 21 filename := r.Filename 22 23 // We'll try to relative-ize our filename here so it's less verbose 24 // in the common case of being in the current working directory. If not, 25 // we'll just show the full path. 26 wd, err := os.Getwd() 27 if err == nil { 28 relFn, err := filepath.Rel(wd, filename) 29 if err == nil { 30 filename = relFn 31 } 32 } 33 34 return fmt.Sprintf("%s:%d,%d", filename, r.Start.Line, r.Start.Column) 35 }