xenomachina / kotlin-argparser

Easy to use and concise yet powerful and robust command line argument parsing for Kotlin
GNU Lesser General Public License v2.1
485 stars 33 forks source link

Lazy parsing #53

Open mykola-dev opened 6 years ago

mykola-dev commented 6 years ago

Hi! I want to parse my args lazily so when i access arg via delegate, parser should parse only this one exact arg. Currently parser run force() method on first delegate access, so all args are being read. Is it possible to disable this behavior and parse 1 arg per delegate access?

xenomachina commented 6 years ago

Sorry, no, that isn't possible.

Can you explain more about what you mean? Parsing of the command line arguments must be performed in the order in which they appear on the command line to be able to distinguish between options, option arguments, and positional arguments. For example -x on the command line could be any of these, depending on what comes before it, and what options have been registered with the parser.

mykola-dev commented 6 years ago

i have such case:

--mandatory_key 123 --optional_key 123 --mandatory2 123

i want all these args to be parsed lazily, so for example if --optional_key hasn't been set and the app haven't read the delegate, the app in this case shouldn't crash

xenomachina commented 6 years ago

You can make --optional_key optional by setting a default value, like null, for it.

xenomachina commented 6 years ago

That said, this is an interesting thought: theoretically it would be possible to add a mode to the parser (or perhaps per-delegate) where it validates delegates lazily.