return fopener.absPath
}
-// File returns an Opener that Opens() a file relative to the calling package.
-func File(relativePath string, ignorePackages ...string) FileOpener {
+// File returns an Opener that Opens() a file.
+// If filename is a relative path, it is considered relative to the *calling
+// file*, not the working directory.
+// If ignorePackages is nonempty, callers in any package specified are ignored.
+func File(filename string, ignorePackages ...string) FileOpener {
opener := new(fileOpener)
- caller, err := getCallStackButt(ignorePackages)
- if err != nil {
- opener.alwaysErr = err
+ if path.IsAbs(filename) {
+ opener.absPath = filename
} else {
- opener.absPath = path.Join(path.Dir(caller), relativePath)
+ caller, err := getCallStackButt(ignorePackages)
+ if err != nil {
+ opener.alwaysErr = err
+ } else {
+ opener.absPath = path.Join(path.Dir(caller), filename)
+ }
}
return opener
}