github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/lang/expressions/noglob/noglob.go (about)

     1  package noglob
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/lmorg/murex/lang"
     7  	"github.com/lmorg/murex/lang/types"
     8  	"github.com/lmorg/murex/utils/json"
     9  )
    10  
    11  // noGlobCmds is a list of all the functions considered unsafe to expand with
    12  // globbing
    13  var noGlobCmds = []string{
    14  	"rx", "!rx", "g", "!g", "cast", "format", "select", "!regexp", "regexp",
    15  	"find", "[", "![", "[[", "test",
    16  	lang.ExpressionFunctionName,
    17  }
    18  
    19  func canGlobCmd(f string) bool {
    20  	for _, sb := range noGlobCmds {
    21  		if f == sb {
    22  			return true
    23  		}
    24  	}
    25  
    26  	return false
    27  }
    28  
    29  // GetNoGlobCmds returns a slice of the noGlobCmds
    30  func GetNoGlobCmds() []string {
    31  	a := make([]string, len(noGlobCmds))
    32  	copy(a, noGlobCmds)
    33  	return a
    34  }
    35  
    36  // ReadNoGlobCmds returns an interface{} of the noGlobCmds.
    37  // This is only intended to be used by `config.Properties.GoFunc.Read()`
    38  func ReadNoGlobCmds() (interface{}, error) {
    39  	return GetNoGlobCmds(), nil
    40  }
    41  
    42  // WriteNoGlobCmds takes a JSON-encoded string and writes it to the noGlobCmds
    43  // slice.
    44  // This is only intended to be used by `config.Properties.GoFunc.Write()`
    45  func WriteNoGlobCmds(v interface{}) error {
    46  	switch v := v.(type) {
    47  	case string:
    48  		return json.Unmarshal([]byte(v), &noGlobCmds)
    49  
    50  	default:
    51  		return fmt.Errorf("invalid data-type. Expecting a %s encoded string", types.Json)
    52  	}
    53  }