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

add an option to validate optional arguments like in a vector. #668

Merged
merged 5 commits into from
Jan 28, 2022

Conversation

phlptp
Copy link
Collaborator

@phlptp phlptp commented Nov 6, 2021

This can resolve some issues with separating positionals from vector arguments

@phlptp
Copy link
Collaborator Author

phlptp commented Nov 6, 2021

For example

std::vector<std::string> vec;
    std::vector<int> ivec;
    app.add_option("pos", vec);
    app.add_option("--args", ivec)->check(CLI::Number);
    app.validate_optional_arguments();

can now parse
--args 1 2 three four

properly withour error

Copy link
Collaborator

@henryiii henryiii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worry about increasing the already quite large API surface, but this looks good. I'm guessing the reason (other than backward compatibility) that this would not be on by default or always on and not a setting would be the error messages are likely poorer with it on?

@phlptp
Copy link
Collaborator Author

phlptp commented Jan 28, 2022

Having it on by default could lead to some confusing results, and it does add computation and the main reason it is needed is symmetry with vector positional arguments in the API, and for situations with positionals and vector arguments.

@henryiii henryiii merged commit a5498be into CLIUtils:main Jan 28, 2022
@henryiii henryiii deleted the optional_validation branch January 28, 2022 16:15
@github-actions github-actions bot added the needs changelog Hasn't been added to the changelog yet label Jan 28, 2022
@henryiii henryiii removed the needs changelog Hasn't been added to the changelog yet label Mar 27, 2022
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

Successfully merging this pull request may close these issues.

2 participants