From: early Date: Wed, 23 Oct 2024 05:00:33 +0000 (-0600) Subject: include.File now accepts absolute paths X-Git-Url: https://git.earlybird.gay/?a=commitdiff_plain;h=87c3901ba1a7b51ae3ebb0d6b256f95cc7c42219;p=today include.File now accepts absolute paths --- diff --git a/include/include.go b/include/include.go index 9678d53..c2ee4fd 100644 --- a/include/include.go +++ b/include/include.go @@ -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 }