Skip to content
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

Lazy parsing #53

Open
mykola-dev opened this issue Apr 5, 2018 · 4 comments
Open

Lazy parsing #53

mykola-dev opened this issue Apr 5, 2018 · 4 comments
Labels

Comments

@mykola-dev
Copy link

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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

@xenomachina
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants