开发者

Boost Program Options Syntax

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...

  • Allow long options after a single -?
  • Allow short options to have more than one character?

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 t开发者_开发百科he 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜