5

How does boost::program_options parse or manage an input when both multitoken and positional options are allowed?

For example:

./app.sample pos1 --multitokenoption a b c d pos2 

How does boost know when a multitokenoption finishes and a positional option begins?

Obviously, the most logical allowed behaviour would be that a multitoken option must be present as last parameter, just as happens with default arguments in function parameters, but the documentation says nothing about it.

ABu
  • 10,423
  • 6
  • 52
  • 103
  • 1
    Why do you think the `multitokenoption` will finish? It will eat all the remaining tokens. If 'pos2' is required, then it will be an exception thrown. – HEKTO May 22 '14 at 21:21

1 Answers1

6

There are three way to mark the end of values for a multitoken option:

  1. Another option:

        ./app.sample pos1 --multitokenoption a b c d --regularoption v pos2
    
  2. Option name for the positional option (almost the #1):

        ./app.sample pos1 --multitokenoption a b c d --pos2 pos2
    
  3. Double-dash:

        ./app.sample pos1 --multitokenoption a b c d -- pos2
    

Otherwise the multi-token option won't know where to stop - nothing magical.

HEKTO
  • 3,876
  • 2
  • 24
  • 45
  • 1
    But boost::program_option has no native support for such double dash, if I'm not wrong. – ABu May 22 '14 at 22:24
  • 2
    It works for me. Boost = 1.55.0, Compiler = GCC 4.8.1, OS = Xubuntu 3.11.10.3 – HEKTO May 22 '14 at 22:41