Make GetOSEnv private and use OS env when nil passed to Evaluate

This commit is contained in:
Ian Gulliver
2025-06-27 12:35:04 -07:00
parent 0e92e0f2f2
commit 7a4fd57b62
3 changed files with 9 additions and 4 deletions
+1 -1
View File
@@ -89,7 +89,7 @@ Related tools:
}
fsys := os.DirFS(opts.RootPath)
output, err := bkl.Evaluate(fsys, files, format, opts.RootPath, wd, bkl.GetOSEnv())
output, err := bkl.Evaluate(fsys, files, format, opts.RootPath, wd, nil)
if err != nil {
fatal(err)
}
+7 -2
View File
@@ -338,8 +338,8 @@ func PreparePathsFromCwd(paths []string, rootPath string) ([]string, error) {
return preparePathsForParser(paths, rootPath, wd)
}
// GetOSEnv returns the current OS environment as a map.
func GetOSEnv() map[string]string {
// getOSEnv returns the current OS environment as a map.
func getOSEnv() map[string]string {
env := make(map[string]string)
for _, e := range os.Environ() {
parts := strings.SplitN(e, "=", 2)
@@ -364,9 +364,14 @@ func FormatOutput(data any, format string) ([]byte, error) {
// Evaluate processes the specified files and returns the formatted output.
// It creates a new bkl instance internally to process the files.
// If env is nil, it uses the current OS environment.
func Evaluate(fsys fs.FS, files []string, format string, rootPath string, workingDir string, env map[string]string) ([]byte, error) {
b := &bkl{}
if env == nil {
env = getOSEnv()
}
evalFiles, err := preparePathsForParser(files, rootPath, workingDir)
if err != nil {
return nil, err
+1 -1
View File
@@ -50,7 +50,7 @@ func WrapOrDie(cmd string) {
}
// Use Evaluate to process the file
output, err := bkl.Evaluate(fsys, []string{realPath}, f, "/", wd, bkl.GetOSEnv())
output, err := bkl.Evaluate(fsys, []string{realPath}, f, "/", wd, nil)
if err != nil {
fatal(err)
}