Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 26 additions & 24 deletions examples/classpath_example.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env kscript

//DEPS com.offbytwo:docopt:0.6.0.20150202,log4j:log4j:1.2.14

//#!/usr/bin/env kotlinc -script -classpath /Users/brandl/.m2/repository/org/docopt/docopt/0.6.0-SNAPSHOT/docopt-0.6.0-SNAPSHOT.jar
Expand All @@ -11,34 +12,35 @@ import java.util.*
// woraround for https://youtrack.jetbrains.com/issue/KT-13347
//val args = listOf("foo", "bar")


var test = File("sdf")
val usage = """
Usage: jl <command> [options] [<joblist_file>]

Supported commands are
submit Submits a job to the underlying queuing system and adds it to the list
add Extracts job-ids from stdin and adds them to the list
wait Wait for a list of jobs to finish
status Prints various statistics and allows to create an html report for the list
kill Removes all jobs of this list from the scheduler queue
up Moves a list of jobs to the top of a queue (if supported by the underlying scheduler)
reset Removes all information related to this joblist.

If no <joblist_file> is provided, jl will use '.jobs' as default
val usage ="""
kscript - Enhanced scripting support for Kotlin on *nix-based systems.

Usage:
kscript ( -t | --text ) <version>
kscript [ --interactive | --idea | --package ] [--] ( - | <file or URL> ) [<args>]...
kscript (-h | --help)
kscript ( --self-update | --clear-cache )

Options:
-t, --text Enable stdin support API for more streamlined text processing [default: latest]
--package Package script and dependencies into self-dependent binary
--idea boostrap IDEA from a kscript
-i, --interactive Create interactive shell with dependencies as declared in script
- Read script from the STDIN
-h, --help Print this text
--self-update Update kscript to the latest version
--clear-cache Wipe cached script jars and urls
"""

val doArgs = Docopt(usage).
parse(args.toList()).
map { it ->
it.key.removePrefix("--").replace("[<>]", "") to {
if (it.value == null) null else Objects.toString(it.value)
}
}
val doArgs = Docopt(usage).parse(args.toList())

println("parsed args are: \n$doArgs (${doArgs.javaClass.simpleName})\n")

println("parsed args are: \n" + doArgs)
doArgs.forEach { (key: Any, value: Any) ->
println("$key:\t$value\t(${value?.javaClass?.canonicalName})")
}

println("Hello from Kotlin!")
println("\nHello from Kotlin!")
for (arg in args) {
println("arg: $arg")
}