File tree Expand file tree Collapse file tree 4 files changed +67
-7
lines changed
Expand file tree Collapse file tree 4 files changed +67
-7
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ repositories {
2626dependencies {
2727// compileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
2828 compile " org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version "
29+ compile " com.offbytwo:docopt:0.6.0.20150202"
2930
3031 testCompile ' junit:junit:4.11'
3132 testCompile " io.kotlintest:kotlintest:2.0.1"
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ package kscript
2+
3+ import org.docopt.Docopt
4+ import java.io.File
5+
6+ /* *
7+ * Helpers to build CLIs with kscript and docopt
8+ *
9+ * @author Holger Brandl
10+ */
11+
12+ /* * Simple Kotlin facade for org.docopt.Docopt.Docopt(java.lang.String) .*/
13+ class DocOpt (args : Array <String >, val usage : String ) {
14+
15+ val myDO by lazy {
16+ Docopt (usage).parse(args.toList()).map {
17+ it.key.removePrefix(" --" ).replace(" [<>]" .toRegex(), " " ) to it.value?.toString()
18+ }.toMap()
19+ }
20+
21+ fun getString (key : String ) = myDO[key]!!
22+ fun getStrings (key : String ) = myDO[key]!!
23+
24+ fun getInt (key : String ) = myDO[key]!! .toInt()
25+
26+ fun getNumber (key : String ) = myDO[key]!! .toFloat()
27+
28+ fun getBoolean (key : String ) = myDO[key]!! .toBoolean()
29+ }
Original file line number Diff line number Diff line change 1+ package kscript.test
2+
3+ import io.kotlintest.matchers.shouldBe
4+ import io.kotlintest.specs.StringSpec
5+ import kscript.DocOpt
6+
7+ /* *
8+ * @author Holger Brandl
9+ */
10+
11+
12+ class DocOptTest : StringSpec () { init {
13+
14+ val args = " -n 7 --pc-only --gtf my.gtf a.fastq b.fastq" .split(" " ).toTypedArray()
15+
16+ val usage = """
17+ Use star to align fastq files against a genome
18+ Usage: star_align.kts [options] <igenome> <fastq_files>...
19+
20+ Options:
21+ --gtf <gtfFile> Custom gtf file instead of igenome bundled copy
22+ --pc-only Use protein coding genes only for mapping and quantification
23+ -n --num-fragments Fragment count used for processing [default: 5]
24+ """
25+
26+ val docopt = DocOpt (args, usage)
27+
28+ docopt.getString(" gtf" ) shouldBe " my.gtf"
29+ docopt.getStrings(" fastq_files" ) shouldBe arrayOf(" a.fastq" , " b.fastq" )
30+
31+ docopt.getInt(" fastq_files" )
32+ docopt.getNumber(" num-fragments" ) shouldBe 7
33+ docopt.getNumber(" num-fragments" ) shouldBe 7
34+ docopt.getNumber(" -n" )
35+ docopt.getBoolean(" pc-only" ) shouldBe true
36+ }
37+ }
You can’t perform that action at this time.
0 commit comments