-
Notifications
You must be signed in to change notification settings - Fork 359
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
Proper way to get path to the config file that was parsed #236
Comments
Wow--you did this and more before I even asked for it!!! Thank you. By the way, what is the process (and delay) for updating CLI11 in vcpkg? I have kind of settled upon vcpkg for getting almost all of my 3rd party dependencies, so I would like to understand how and when CLI11 changes make it into the vcpkg head. (Should I make this question a separate issue?) |
I just discovered another way to get the config value using auto config = app.set_config("--config", config_val);
config->check([&](const std::string &config_arg) {
config_val = config_arg;
return config_arg;
}); This is my first attempt using a custom validator. While your PR changes provide exactly what I need, this (ab)use of |
I needed it for some options where I don't have any place to store the result until after the parsing, so this made it much easier to deal with that in a nice way, and make converting from boost::program_option somewhat more straightforward. |
I think in your check function you probably need to return an empty string otherwise it will throw an error of some kind since the return string usually goes into an error message about the validation failing. |
Or you could put that into the translate instead of the check |
Yes, @phlptp is correct. You'll want to return an empty string for "no error". However, what about running each? That sounds pretty close to what you want. auto config = app.set_config("--config", config_val);
config->each([&config_val](const std::string &config_arg) {
config_val = config_arg;
}); |
Yes, |
What is the right way to get the path to the config file that was parsed? For debugging purposes, I want to log the path to the config file that was loaded. Since the default path could have been overridden during argument parsing, I need the Option returned by the
app->get_config_ptr()
call to tell me. At least this is how I have done it:Is there a better way? If not, should there be a better way? If this is not obvious, should this be added to the documentation?
The text was updated successfully, but these errors were encountered: