]> git.earlybird.gay Git - today/commitdiff
include.File now accepts absolute paths
authorearly <me@earlybird.gay>
Wed, 23 Oct 2024 05:00:33 +0000 (23:00 -0600)
committerearly <me@earlybird.gay>
Wed, 23 Oct 2024 05:00:33 +0000 (23:00 -0600)
include/include.go

index 9678d53519ce49b8cfd19d757ae49aabaaec9db6..c2ee4fd946716a51c3572bed67a66ebf400d0348 100644 (file)
@@ -38,14 +38,21 @@ func (fopener *fileOpener) FileName() string {
        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
 }