Is it possible to specify an argument with boost::program_options with short option only?
The answer given here is to use allow_long_disguise, which will result in long options being acceptable with a single dash. Is there any way to make some options short-only (single dash and single character), without using allow_long_disguise?
You could write your own parser
namespace po = boost::program_options;
std::pair<std::string, std::string> short_flag_parser(const std::string& s)
{
// one letter arguments work with single dash
if (s[0] == '-' && s.size() == 2) {
return make_pair(s.substr(1), std::string());
} else {
return make_pair(std::string(), std::string());
}
};
int main() {
desc.add_options()
("help, h", "produce help message");
po::variables_map vm;
po::store(po::command_line_parser(ac, av).options(desc).extra_parser(short_flag_parser).run(), vm);
po::notify(vm);
if (vm.count("help")) {
std::cout << desc;
return;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With