-
Notifications
You must be signed in to change notification settings - Fork 34
Description
I have lately been exploring kotlin for scripting purposes, using https://github.com/holgerbrandl/kscript.
Kotlin-argparsers really shines in scripts because it's concise and still provides nice error messages.
On of the differences between regular Kotlin code and a KScript is that the script does not contain a main method. Instead it gets executed from top to bottom. Not having a main method suddenly makes the mainBody
lambda look ugly, because I always have write something like this:
val parsedArgs = mainBody {
ArgParser(args).parseInto(::Args)
}
The mainBody
has to be there because otherwise we get ugly stacktraces instead of a simple error message like "missing option X". It would be much nicer if there was a method like parseInto() that would already contain the exception handling part so we could simply write:
val parsedArgs = ArgParser(args).parseIntoOrExit(::Args)