You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is an issue which was only slightly mentioned in #903, so I will describe this specific case here in more details.
Basic example:
auto CliApp = new CLI::App("myapp");
auto sub1 = CliApp->add_subcommand("sub1");
std::filesystem::path someFile = "";
sub1->add_option("-f,--file", someFile)->envname("SOME_FILE")->required()->expected(1)->check(CLI::ExistingFile);
try
{
CliApp->parse(argsCount, args);
}
catch (const CLI::ParseError& e)
{
return CliApp->exit(e);
}
Make sure %SOME_FILE% env var is defined as invalid/non-existing file path.
Then call the app like that: myapp.exe sub1 -h:
-Normally it should only display the help about sub1 expectations & requirements and exit, as that's a completely separate control flow path for the app, just like displaying the app version with -v.
-Actually it fails CLI::ExistingFile validator check, suggesting to Run with --help for more information.. But it's impossible to call for help.
The text was updated successfully, but these errors were encountered:
The issue stems from the fact that validation errors are given higher precedence then the help "error" trigger. This is a deliberate choice. In most cases if you really want help you can remove other arguments. In the case of environmental values, that fail validation there is no way to not trigger it. This is probably not a good situation. The fix I would propose is to make the environmental variables do a pre-validation, like the validate_positionals() modifier. Except in this case it is not an optional modifier. It would be like not having the environmental variable defined to begin with if it doesn't pass validation. This gets around the issue described in the bug report. There might be other possible solutions if CLI11 were to ever work through all the details to make it work with no exceptions, but for now I think prevalidating the results for environmental variables is probably the best and simplest approach. I will make a PR shortly and have @henryiii check to make sure that is approach we want to take.
This is an issue which was only slightly mentioned in #903, so I will describe this specific case here in more details.
Basic example:
Make sure
%SOME_FILE%
env var is defined as invalid/non-existing file path.Then call the app like that:
myapp.exe sub1 -h
:-Normally it should only display the help about
sub1
expectations & requirements and exit, as that's a completely separate control flow path for the app, just like displaying the app version with-v
.-Actually it fails
CLI::ExistingFile
validator check, suggesting toRun with --help for more information.
. But it's impossible to call for help.The text was updated successfully, but these errors were encountered: