Boost logo

Boost :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2005-05-06 03:06:49


Since this was the most requested change for program_options, I though I'd
post specific announcement.

I've committed a change that finally makes
command_line_parser::allow_unregistered to work as expected. Assuming you get
command line like:

   --foo=10 --bar=15 --biz 5 -cd -d10

and registered options are "foo" and "-c", where "-c" takes no value,
parsing that command line will give you the following list of options:

   ("foo", "10")
   ("bar", "15") *
   ("biz", ) *
   ("5") (positional)
   ("-c", )
   ("-d", ) *
   ("-d", "10) *

The 'option' instances corresponding to option marked with '*' will have
'unregistered' member set to true.

With that information it's possible to:
1. Collect all unregistered option as process them separately.
2. Construct a new command line from unregistered options and pass it to some
application. In the above example, reconstructed command like would be

   --bar=15 --biz 5 -d -d10

There are some notes of interest.
First, the option class don't keep the original tokens it was created from.
The unregistered option can technically arrive from user-provided 'additional
parser' where 'original tokens' are not even present.

Second, for 'sticky' short options, like '-cd' above, the library can break
them in parts. Again, in example we get:

   ("-c", )
   ("-d", ) *

The 'c' letter is recognized, and the 'd' letter is not. I find this behaviour
better than marking the entire '-cd' as unrecognised.

Finally, the new functionality might not work nice with long options that
start with a single dash (allow_long_disguise style option):

   -foo

will be considered as short option '-f' with value 'oo', and never as long
option 'foo'.

Feedback is appreciated!

I was also asked for 'allow_unregistered' support for config file. I agree
this might be good, but given that config file never supported it in any
form, it's clearly a new feature, and will have to wait till 1.33 is
released.

- Volodya


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk