From 87c3901ba1a7b51ae3ebb0d6b256f95cc7c42219 Mon Sep 17 00:00:00 2001 From: early Date: Tue, 22 Oct 2024 23:00:33 -0600 Subject: [PATCH] include.File now accepts absolute paths --- include/include.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) 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 } -- 2.39.5