The problem seems to be related to how boost :: program_options options_description is executed.
int main(int argc, char* argv[])
{
boost::program_options::options_description desc("CmdLine utility");
desc.add_options()
("hel", "hel message")
("help", "produce help message")
("helps","helps message")
;
boost::program_options::variables_map vm;
boost::program_options::store(boost::program_options::parse_command_line(argc, argv,desc), vm);
boost::program_options::notify(vm);
if(vm.count("help")) {
std::cout << desc << std::endl;
}
if(vm.count("helps")) {
std::cout << "helps..." << std::endl;
}
if(vm.count("hel")) {
std::cout << "hel..." << std::endl;
}
return 0;
}
Output -
C:\code>cmd.exe --helps
helps...
C:\code>cmd.exe --help
helps...
C:\code>cmd.exe --hel
helps...
The output changes if I change the order of adding options using a call add_options(). It also looks like program_options does not execute the full command line, so even if you enter a substring of the parameter, it will treat it as valid without doing a full string comparison. If this is a boost :: program_options function, is there a way to get it to perform exact string matching rather than doing it with a substring? (I am using Boost version 1.42)