databricks-cli/libs/dyn/location.go

29 lines
528 B
Go
Raw Normal View History

package dyn
2023-10-20 12:56:59 +00:00
import (
"fmt"
"path/filepath"
)
2023-10-20 12:56:59 +00:00
type Location struct {
File string
Line int
Column int
}
2024-05-27 12:32:01 +00:00
// nilLocation is a convenient constant for a nil location.
// TODO: Remove this constant and rely on the file path in the location?
var nilLocation = Location{}
2023-10-20 12:56:59 +00:00
func (l Location) String() string {
return fmt.Sprintf("%s:%d:%d", l.File, l.Line, l.Column)
}
func (l Location) Directory() (string, error) {
if l.File == "" {
return "", fmt.Errorf("no file in location")
}
return filepath.Dir(l.File), nil
}