Skip to content

Include exception handling in force parse #64

@exaV

Description

@exaV

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)

here is a full example

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions