Opened 12 years ago

Last modified 8 years ago

#4510 new Bugs

[program_options]: implicit_value and positional options conflict

Reported by: Soren Soe <soren.soe@…> Owned by: Vladimir Prus
Milestone: Boost 1.44.0 Component: program_options
Version: Boost 1.44.0 Severity: Problem
Keywords: Cc:

Description

Hello,

Thanks for a great library. I just updated to 1.43 and it appears options with implicit values no longer work if there are also positional options.

In fact libs/src/program_options/example/options_description.cpp fails in 1.43:

1.43% options_description --verbose foo
in option 'verbose': invalid option value

In 1.38 this worked fine

1.38% options_description --verbose foo
Input files are: foo
Verbosity enabled.  Level is 1
Optimization level is 10
Listen port is 0

I briefly looked at the library source code and see new code added in cmdline.cpp:

 /* If an key option is followed by a positional option,
     can can consume more tokens (e.g. it's multitoke option),
    give those tokens to it.  */
 ...

It seems that in order to make implicit options work in presence of positional options, the semantic()->max_tokens() function must return 0, that is, you can never specify a value for an implicit option. I don't know if this is desired, but it will work for me.

Thank you,

Soren Soe

Change History (3)

comment:1 by mdecker6@…, 8 years ago

Is anyone going to fix this? Everything is pretty much as Soren says.

As for if this was desired, this is not how it is documented and not how this typically should behave. That is, options with implicit_values should never consume positional options. Never being able to specify a value for an implicit value, negates the purpose of implicit values (as these can be accomplished with just bool_switch) and there is no other option that I can think of to do this.

Here is the documentation for reference:

Specifies an implicit value, which will be used if the option is given, but without an adjacent value. Using this implies that an explicit value is optional, but if given, must be strictly adjacent to the option, i.e.: '-ovalue' or '--option=value'. Giving '-o' or `--option' will cause the implicit value to be applied.

comment:2 by Vladimir Prus, 8 years ago

Probably the most reliable way to get this fixed is to submit a pull request; otherwise it won't get fixed for at least two weeks of upcoming public holidays, and then maybe some time more.

in reply to:  2 comment:3 by anonymous, 8 years ago

Replying to vladimir_prus:

Probably the most reliable way to get this fixed is to submit a pull request; otherwise it won't get fixed for at least two weeks of upcoming public holidays, and then maybe some time more.

Ok, cool. Thank you.

Note: See TracTickets for help on using tickets.