Skip to content

Commit 7bf014c

Browse files
committed
added -t/--text argument to enable support api
1 parent 99ec901 commit 7bf014c

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/main/kotlin/kscript/app/Kscript.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Use '--self-update' to wipe cached script jars and urls
3535
3636
Options:
3737
-i --interactive Create interactive shell with dependencies as declared in script
38+
-t --text Enable stdin support API for more streamlined text processing
3839
--idea Open script in temporary Intellij session
3940
4041
Copyright : 2017 Holger Brandl
@@ -86,7 +87,7 @@ fun main(args: Array<String>) {
8687

8788
// Resolve the script resource argument into an actual file
8889
val scriptResource = docopt.getString("script")
89-
val scriptFile = prepareScript(scriptResource)
90+
val scriptFile = prepareScript(scriptResource, enableSupportApi = docopt.getBoolean("text"))
9091

9192

9293
val scriptText = scriptFile.readLines()
@@ -263,7 +264,7 @@ private fun versionCheck() {
263264
}
264265
}
265266

266-
fun prepareScript(scriptResource: String): File {
267+
fun prepareScript(scriptResource: String, enableSupportApi: Boolean): File {
267268
var scriptFile: File?
268269

269270
// map script argument to script file
@@ -304,7 +305,8 @@ fun prepareScript(scriptResource: String): File {
304305
var script = scriptResource.trim()
305306

306307
//auto-prefix one-liners with kscript-support api
307-
if (numLines(script) == 1 && (script.startsWith("lines") || script.startsWith("stdin"))) {
308+
// if (numLines(script) == 1 && (script.startsWith("lines") || script.startsWith("stdin"))) {
309+
if (enableSupportApi) {
308310
val prefix = """
309311
//DEPS com.github.holgerbrandl:kscript:1.2.2
310312

test/test_suite.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ assert "source ${KSCRIPT_HOME}/test/resources/direct_script_arg.sh" "kotlin rock
3535
## also allow for empty programs
3636
assert "kscript ''" ""
3737

38+
## provide script as direct argument
39+
assert 'kscript "println(1+1)"' '2'
40+
41+
3842
## provide script via stidin
3943
assert "echo 'println(1+1)' | kscript -" "2"
4044

@@ -132,13 +136,12 @@ assert_end dependency_lookup
132136
## support_api
133137

134138
## make sure that one-liners include support-api
135-
assert 'echo "foo${NL}bar" | kscript "stdin.print()"' $'foo\nbar'
139+
assert 'echo "foo${NL}bar" | kscript -t "stdin.print()"' $'foo\nbar'
136140
#echo "$'foo\nbar' | kscript 'stdin.print()'
137141

138-
assert 'kscript "println(1+1)"' '2'
139142

140143

141-
assert_statement 'echo "foo${NL}bar" | kscript "stdin.split().select(1, 2, -3)"' "" "[ERROR] Can not mix positive and negative selections" 1
144+
assert_statement 'echo "foo${NL}bar" | kscript --text "stdin.split().select(1, 2, -3)"' "" "[ERROR] Can not mix positive and negative selections" 1
142145

143146
assert_end support_api
144147

0 commit comments

Comments
 (0)