Comments (2)
Good idea!
One gotcha with this: if you only return
from (an inline version of) mainBody
's lambda sometimes, it's fine, but if you do it on every code path you start getting errors like:
Kotlin: 'Nothing' return type needs to be specified explicitly
Kotlin: This function must return a value of type Nothing
This is because returning from main
in every code path of mainBody
means that mainBody
's return type is now Nothing
(as it always exits prematurely), and the type of main
is the same as mainBody
in the typical usage.
A workaround (which also works right now, BTW) is to use a qualified return
:
return@mainBody
This returns from mainBody
, rather than from main
, but in the typical usage that's pretty much the same thing.
Another work around is to write something like this:
fun main(args: Array<String>) {
mainBody {
...
return
}
}
instead of:
fun main(args: Array<String>) = mainBody {
...
return
}
This decouples the type from mainBody
's lambda from main
, so Kotlin is happy.
from kotlin-argparser.
Thank you for that detailed answer!
I think using return@mainBody
is a fine solution.
from kotlin-argparser.
Related Issues (20)
- Allow '.' as Separator in Options and Arguments HOT 2
- Hierarchical arguments
- Print help when catching SystemExitException HOT 1
- Is it possible to allow number parameters HOT 3
- Incorrect example main function in README.md HOT 1
- Readme example does not work HOT 3
- Exception in thread "main" com.xenomachina.argparser.ShowHelpException: Help was requested HOT 3
- InvalidArgumentName when argument name has trailing digit HOT 2
- Allow escaping strings HOT 6
- Include exception handling in force parse HOT 3
- Make `mainBody` behavior the default when parsing args HOT 3
- Help section titles should be capitalized HOT 2
- Interest in better support for sub parsers HOT 2
- Don't be too strict with positional and positionalList names
- Influcence exit behaviour
- better handling of long parameter names in the default formatter
- Is this project dead? HOT 1
- Support options of the form "-<number>" (hyphen immediately followed by a number)
- JCenter end of life
- kotlin-argparser and native?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kotlin-argparser.