I'm using boost::program_options to read the users' input from the command line argument. It works very nicely and allows me to output helpful usage messages and validate input properly. However, by default long option names must come after a double-dash for example --my_long_option
and short options come after a single dash and must be a single character, example; -m
.
Is there a way to either...
-
?Thus allowing me to have command lines which looks like
./a.out -myopt1 foo -myopt2 bar
The two possibilities should have the same effect though from a programming point of view the first would be better. I had a look at boost::program_options::command_line_style but it doesn't look like it can do what I need.
Thanks
Edit: Further to accepted answer below to get it to use that style one must add the following code (following the naming convention of the boost docs)
po::store(
po::command_line_parser(ac,av)
.options(desc)
.style(
po::command_line_style::unix_style
| po::command_line_style::allow_long_disguise)
.run(),
vm);
Short options by definition have just one character. If they had more, they'd be long options.
To allow long options to start with a single dash, include the allow_long_disguise
command-line style, as described on the documentation page you linked to:
It's possible to introduce long options by the same character as short options, see allow_long_disguise.
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