File tree Expand file tree Collapse file tree 2 files changed +11
-10
lines changed
Expand file tree Collapse file tree 2 files changed +11
-10
lines changed Original file line number Diff line number Diff line change 11#! /bin/bash
22
3- KSCRIPT_VERSION=1.4
3+ KSCRIPT_VERSION=1.4.1
44
55# # make sure that all requirements (java, kotlinc, maven) to run kscript are met
66assertInPath (){ if [ -z " $( which $1 ) " ]; then echo " [ERROR] Could not locate '$1 '" 1>&2 ; exit 1; fi }
77
8+ # # trim whitespace from a string
9+ trim () { while read -r line; do echo " $line " ; done ; }
10+
811assertInPath kotlinc
912assertInPath mvn
1013assertInPath curl
144147# # note: -e also supports non-regular files in contrast to -f
145148if [[ " $scriptFile " != * kts ]] && [[ ! -e ${scriptFile} ]]; then
146149 # # auto-prefix one-liners with kscript-support api
147- if [[ $( echo " ${scriptFile} " | wc -l) -eq 1 ]]; then
148- scriptFile=$' //DEPS com.github.holgerbrandl:kscript:1.2\n import kscript.text.*\n val lines = resolveArgFile(args)\n\n ' ${scriptFile}
150+ # if [[ $(echo "${scriptFile}" | wc -l) -eq 1 ]]; then ## old approach
151+ # http://stackoverflow.com/questions/2172352/in-bash-how-can-i-check-if-a-string-begins-with-some-value
152+ trimmedScript=$( echo " ${scriptFile} " | tr -d ' \n' )
153+ if [[ $trimmedScript == lines.* ]] || [[ $trimmedScript == stdin.* ]] ; then
154+ scriptFile=$' //DEPS com.github.holgerbrandl:kscript:1.2.1\n import kscript.text.*\n val lines = resolveArgFile(args)\n\n ' ${scriptFile}
149155 fi
150156
151157 scriptHash=$( kscript_md5 <( echo " $scriptFile " ) )
173179if [ $( grep " ^// DEPS" ${scriptFile} | wc -l) -gt 0 ]; then
174180 echo " [ERROR] Dependencies must be declared by using the line prefix //DEPS" 1>&2 ; exit 1;
175181fi
176- trim () { while read -r line; do echo " $line " ; done ; }
177182dependencies=$( grep " ^//DEPS" ${scriptFile} | cut -f2- -d' ' | trim | tr ' ,;\n' ' ' )
178183
179184
Original file line number Diff line number Diff line change @@ -102,14 +102,10 @@ assert 'echo "foo${NL}bar" | kscript "stdin.print()"' $'foo\nbar'
102102# echo "$'foo\nbar' | kscript 'stdin.print()'
103103
104104assert ' echo "foo${NL}bar" | kscript "stdin.print()"' $' foo\n bar'
105+ assert ' kscript "println(1+1)"' ' 2'
105106
106- # # todo renable once support v1.3 is live on jcenter
107- # assert_statement 'echo "foo${NL}bar" | kscript "stdin.split().select(1, 2, -3)"' "" "[ERROR] Can not mix positive and negative selections" 1
108107
109-
110-
111- # # requirement checkig using support api
112- assert_statement ' kscript "kscript.stopIfNot(1==23){\"condition not met\"}"' " " " [ERROR] condition not met" 1
108+ assert_statement ' echo "foo${NL}bar" | kscript "stdin.split().select(1, 2, -3)"' " " " [ERROR] Can not mix positive and negative selections" 1
113109
114110assert_end support_api
115111
You can’t perform that action at this time.
0 commit comments