From 32974d9d37ed8454734c42a428eb5ad132491baf Mon Sep 17 00:00:00 2001 From: "C.A.B" Date: Fri, 6 Apr 2018 00:52:36 -0400 Subject: [PATCH 1/2] Use kscript command options as an example of usage DocOpt --- examples/classpath_example.kts | 49 +++++++++++++++++----------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/examples/classpath_example.kts b/examples/classpath_example.kts index 6b031304..7bca47da 100755 --- a/examples/classpath_example.kts +++ b/examples/classpath_example.kts @@ -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 @@ -11,34 +12,34 @@ 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 [options] [] - -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 is provided, jl will use '.jobs' as default +val usage =""" +kscript is a wrapper to "interpret" the Kotlin source file in the way similar to SHELL script or "kotlinc -script" + +Usage: + kscript ( -t | --text ) + kscript [ --interactive | --idea | --package ] [--] [ - | ]... + kscript (-h | --help) + kscript --self-update + +Options: + -t, --text text processing mode + --package deploy scripts as standalone binaries + --idea boostrap IDEA from a kscript + --interactive treat yourself a REPL + - to read script from the STDIN + -h, --help this screen + --self-update kscript updates itself """ -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") } From 3c83ed888b117d569b33bb2e53b3c591fa018cd6 Mon Sep 17 00:00:00 2001 From: "C.A.B" Date: Fri, 6 Apr 2018 23:34:20 -0400 Subject: [PATCH 2/2] Improve text of the Usage example --- examples/classpath_example.kts | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/examples/classpath_example.kts b/examples/classpath_example.kts index 7bca47da..8e6fddd4 100755 --- a/examples/classpath_example.kts +++ b/examples/classpath_example.kts @@ -13,22 +13,23 @@ import java.util.* //val args = listOf("foo", "bar") val usage =""" -kscript is a wrapper to "interpret" the Kotlin source file in the way similar to SHELL script or "kotlinc -script" +kscript - Enhanced scripting support for Kotlin on *nix-based systems. Usage: - kscript ( -t | --text ) - kscript [ --interactive | --idea | --package ] [--] [ - | ]... + kscript ( -t | --text ) + kscript [ --interactive | --idea | --package ] [--] ( - | ) []... kscript (-h | --help) - kscript --self-update + kscript ( --self-update | --clear-cache ) Options: - -t, --text text processing mode - --package deploy scripts as standalone binaries - --idea boostrap IDEA from a kscript - --interactive treat yourself a REPL - - to read script from the STDIN - -h, --help this screen - --self-update kscript updates itself + -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())