Skip to content

Instantly share code, notes, and snippets.

@tpanagos
Created July 22, 2021 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tpanagos/fb8ca4afb16b00862429ffc87dc65348 to your computer and use it in GitHub Desktop.
Save tpanagos/fb8ca4afb16b00862429ffc87dc65348 to your computer and use it in GitHub Desktop.
Nifi Expression Language Testing from the command-line for 1.12.1
// eg. groovy testEL.groovy -D filename=hello '${filename:append("_world")}'
@Grab(group='org.apache.nifi', module='nifi-expression-language', version='1.12.1')
import org.apache.nifi.attribute.expression.language.*
def cli = new CliBuilder(usage:'groovy testEL.groovy [options] [expressions]',
header:'Options:')
cli.help('print this message')
cli.D(args:2, valueSeparator:'=', argName:'attribute=value',
'set value for given attribute')
def options = cli.parse(args)
if(!options.arguments()) {
cli.usage()
return 1
}
def attrMap = [:]
def currKey = null
options.Ds?.eachWithIndex {o,i ->
if(i%2==0) {
currKey = o
} else {
attrMap[currKey] = o
}
}
options.arguments()?.each {
def q = Query.compile(it)
def sec = new StandardEvaluationContext(attrMap ?: null)
println q.evaluate(sec)
}
@tpanagos
Copy link
Author

@MostHated
Copy link

I had to add import groovy.cli.commons.CliBuilder otherwise I was getting unable to resolve class CliBuilder error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment