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

Support parsing arguments partially #18

Open
igorcoding opened this issue Jul 5, 2018 · 2 comments
Open

Support parsing arguments partially #18

igorcoding opened this issue Jul 5, 2018 · 2 comments

Comments

@igorcoding
Copy link

It is very useful to parse args partially, like in Python - https://docs.python.org/3/library/argparse.html#partial-parsing

Typical usecase - add additional options, depending on the value of another option.

@igorcoding igorcoding changed the title Support parsing only known arguments Support parsing arguments partially Jul 5, 2018
@iridiumlynx
Copy link

igorcoding, there is mutex(...) method for your use-case.

@igorcoding
Copy link
Author

How does it solve my use case?
My goal is to call parse multiple times, for example

  1. User calls program with arguments ./my_program --template=basic --basic_option1=value1
  2. In lua we define argument --template to argparse
  3. Call a hypothetical parse_known_args to parse only arguments we defined and ignore others (because right now parse() fails if encounters unknown args)
  4. Then depending on value of passed template argument we add additional arguments to argparse, using parser:option("--basic_option1", "Option 1")
  5. And then call parse() again and receiving a complete set of user-specified arguments.

This is also useful with the help messages - collect all arguments and only then display all valid options even if user specified template, i.e. ./my_program --template=basic -h

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

No branches or pull requests

2 participants