Skip to content

Commit 65e07ea

Browse files
committed
updated landing page to include inlined usage examples
1 parent 8d80e31 commit 65e07ea

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,41 @@ println("Parsed script arguments are: \n" + doArgs.joinToString())
6060
Note: It might feel more intuitive to provide dependencies as an argument to `kscript`, however because of the way the shebang line works on Linux this is not possible.
6161

6262

63+
64+
Inline Usage
65+
============
66+
67+
You can even inline `kscript` solutions into larger scripts, because `kscript` can read from stdin as well. So, depdending your preference you could simply pipe a kotlin snippet into `kscript`
68+
69+
```
70+
echo '
71+
println("hello kotlin")
72+
' | kscript
73+
```
74+
75+
76+
or do the same using `heredoc` (preferred solution) which gives you some more flexibility to also use single quotes in your script:
77+
```
78+
kscript - <<"EOF"
79+
println("hello kotlin and heredoc")
80+
EOF
81+
```
82+
83+
Since the piped content is considered as a regular script it can also have dependencies
84+
```
85+
kscript - <<"EOF"
86+
//DEPS org.docopt:docopt:0.6.0-SNAPSHOT log4j:log4j:1.2.14
87+
88+
import org.docopt.Docopt
89+
val docopt = Docopt("Usage: jl <command> [options] [<joblist_file>]")
90+
91+
println("hello again")
92+
EOF
93+
```
94+
95+
Inlined _kscripts_ are also cached based on `md5` checksum, so running the same snippet again will use a cached jar (sitting in `$TMPDIR`).
96+
97+
6398
References
6499
============
65100

0 commit comments

Comments
 (0)