-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include exception handling in force parse #64
Comments
Thanks for reporting this. I've never used KScript, but ensuring that Kotlin-argparser works well with it sounds like a great idea. For now, would it be possible to replace this:
with this?
Making this less verbose would be nice, but part of the reason the "mainBody" is separate from "parseInto" is to make testing easier. I should probably at least make this more clear in kotlin-argparser-example. |
I reported this issue because I am not willing to put the whole script into a lambda in the first place for the same reasons I do not want to have a main method. The example I provided is somewhat minimal so maybe it did not seem significant there. However in any meaningful script most of the code would be wrapped into the mainBody lambda and thus have one level of indentation. Additional indentation makes the script harder to read, especially because usually there will be at least one or two more levels of indentation (say an I was already quite pleased when I realised I could use
which lets me get around having additional indentation for the rest of the script. However having the Coincidentally the maintainer of Kscript also opened an issue relating to this #65 which indicated that I'm not the only one with this issue. I understand your reservations you have regarding testability, however as a user I would still much prefer not having to write |
Would it help testability if you declared the function I need as an extension function on Argparser in its own file? You could then test this file on its own. I'm thinking of this:
Of course the name could be different |
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: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:here is a full example
The text was updated successfully, but these errors were encountered: