kotlin-argparser icon indicating copy to clipboard operation
kotlin-argparser copied to clipboard

Readme example does not work

Open engelkes-finstreet opened this issue 7 years ago • 3 comments

Currently I try to use kotlin-argparser in one of my projects. Unfortunately even a simple example throws an error.

class MyArgs(parser: ArgParser) { val test by parser.flagging("-t", "--test", help = "Test") }

fun main(args: Array<String>) = mainBody { ArgParser(args).parseInto(::MyArgs).run { println("Hello, ${test}!") } }

In IntelliJ I set the program argument to i but I get the error unrecognized option '-t' After debugging I found that in the method parseShortOpt the shortOptionDelegates only contains the help delegate.

Does anybody have a solution for this?

engelkes-finstreet avatar Jun 29 '18 15:06 engelkes-finstreet

Unfortunately, I can't reproduce this problem.

I tried replacing the contents of kotlin-argparser-example's Main.kt (except for imports and package statement) with your code, and it functioned correctly:

$ ./gradlew installDist

BUILD SUCCESSFUL in 0s
4 actionable tasks: 1 executed, 3 up-to-date
$ build/install/kotlin-argparser-example/bin/kotlin-argparser-example --help
usage: build/install/kotlin-argparser-example/bin/kotlin-argparser-example
         [-h] [-t]

optional arguments:
  -h,      show this help message and exit
  --help

  -t,      Test
  --test

$ build/install/kotlin-argparser-example/bin/kotlin-argparser-example 
Hello, false!
$ build/install/kotlin-argparser-example/bin/kotlin-argparser-example -t
Hello, true!

What do you mean by "In IntelliJ I set the program argument to i"? What is "i"?

xenomachina avatar Jun 29 '18 17:06 xenomachina

Sorry for not being clear with IntelliJ. In IntelliJ you can set your run configuration and edit VM options and Program Arguments with which the application should start. Setting the Program Argument to -t gives the error described above.

engelkes-finstreet avatar Jul 02 '18 06:07 engelkes-finstreet

Have you tried running it from the command line?

xenomachina avatar Jul 02 '18 17:07 xenomachina