aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/terraform/tfdiags/source_range.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/tfdiags/source_range.go')
-rw-r--r--vendor/github.com/hashicorp/terraform/tfdiags/source_range.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/terraform/tfdiags/source_range.go b/vendor/github.com/hashicorp/terraform/tfdiags/source_range.go
new file mode 100644
index 0000000..3031168
--- /dev/null
+++ b/vendor/github.com/hashicorp/terraform/tfdiags/source_range.go
@@ -0,0 +1,35 @@
1package tfdiags
2
3import (
4 "fmt"
5 "os"
6 "path/filepath"
7)
8
9type SourceRange struct {
10 Filename string
11 Start, End SourcePos
12}
13
14type 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.
20func (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}