improved position of some common functions

This commit is contained in:
2024-06-09 07:38:29 +02:00
parent 53bcf90d2a
commit 8eb2d77ea3
4 changed files with 33 additions and 38 deletions
+24 -19
View File
@@ -13,6 +13,11 @@ import (
"strings"
)
const (
ENV_EXPR_SOURCE_PATH = "EXPR_PATH"
ENV_EXPR_PLUGIN_PATH = "EXPR_PLUGIN_PATH"
)
func checkStringParamExpected(funcName string, paramValue any, paramPos int) (err error) {
if !(IsString(paramValue) /*|| isList(paramValue)*/) {
err = fmt.Errorf("%s(): param nr %d has wrong type %s, string expected", funcName, paramPos+1, typeName(paramValue))
@@ -20,8 +25,16 @@ func checkStringParamExpected(funcName string, paramValue any, paramPos int) (er
return
}
func addEnvImportDirs(dirList []string) []string {
if dirSpec, exists := os.LookupEnv(ENV_EXPR_PATH); exists {
func addSourceEnvImportDirs(varName string, dirList []string) []string {
return addEnvImportDirs(ENV_EXPR_SOURCE_PATH, dirList)
}
func addPluginEnvImportDirs(varName string, dirList []string) []string {
return addEnvImportDirs(ENV_EXPR_PLUGIN_PATH, dirList)
}
func addEnvImportDirs(envVarName string, dirList []string) []string {
if dirSpec, exists := os.LookupEnv(envVarName); exists {
dirs := strings.Split(dirSpec, ":")
if dirList == nil {
dirList = dirs
@@ -32,22 +45,8 @@ func addEnvImportDirs(dirList []string) []string {
return dirList
}
/*
func addPresetDirs(ctx ExprContext, ctrlKey string, dirList []string) []string {
if dirSpec, exists := getControlString(ctx, ctrlKey); exists {
dirs := strings.Split(dirSpec, ":")
if dirList == nil {
dirList = dirs
} else {
dirList = append(dirList, dirs...)
}
}
return dirList
}
*/
func addSearchDirs(ctx ExprContext, endingPath string, dirList []string) []string {
if dirSpec, exists := getControlString(ctx, ControlSearchPath); exists {
func addSearchDirs(endingPath string, dirList []string) []string {
if dirSpec, exists := getControlString(ControlSearchPath); exists {
dirs := strings.Split(dirSpec, ":")
if dirList == nil {
dirList = dirs
@@ -64,6 +63,12 @@ func addSearchDirs(ctx ExprContext, endingPath string, dirList []string) []strin
return dirList
}
func buildSearchDirList(endingPath, envVarName string) (dirList []string) {
dirList = addEnvImportDirs(envVarName, dirList)
dirList = addSearchDirs(endingPath, dirList)
return
}
func isFile(filePath string) bool {
info, err := os.Stat(filePath)
return (err == nil || errors.Is(err, os.ErrExist)) && info.Mode().IsRegular()
@@ -93,7 +98,7 @@ func makeFilepath(filename string, dirList []string) (filePath string, err error
filePath = searchAmongPath(filename, dirList)
}
if len(filePath) == 0 {
err = fmt.Errorf("source file %q not found", filename)
err = fmt.Errorf("file %q not found", filename)
}
return
}