mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-30 10:47:14 -06:00
05caff2ca3
This is part of a general effort to move all of Terraform's non-library package surface under internal in order to reinforce that these are for internal use within Terraform only. If you were previously importing packages under this prefix into an external codebase, you could pin to an earlier release tag as an interim solution until you've make a plan to achieve the same functionality some other way.
36 lines
763 B
Go
36 lines
763 B
Go
package tfdiags
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
type SourceRange struct {
|
|
Filename string
|
|
Start, End SourcePos
|
|
}
|
|
|
|
type SourcePos struct {
|
|
Line, Column, Byte int
|
|
}
|
|
|
|
// StartString returns a string representation of the start of the range,
|
|
// including the filename and the line and column numbers.
|
|
func (r SourceRange) StartString() string {
|
|
filename := r.Filename
|
|
|
|
// We'll try to relative-ize our filename here so it's less verbose
|
|
// in the common case of being in the current working directory. If not,
|
|
// we'll just show the full path.
|
|
wd, err := os.Getwd()
|
|
if err == nil {
|
|
relFn, err := filepath.Rel(wd, filename)
|
|
if err == nil {
|
|
filename = relFn
|
|
}
|
|
}
|
|
|
|
return fmt.Sprintf("%s:%d,%d", filename, r.Start.Line, r.Start.Column)
|
|
}
|