[program_option] allow_unregistered now works

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

On 5/6/05, Vladimir Prus <ghost@cs.msu.su> wrote:
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.
I agree that this is the desirable behavior.
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'.
Would this only be if "f" is a registered option, or even if it is unregistered? I'd think in the unregistered case you'd end up with -f and two -o's as in the -cd case above. Whichever the case, I agree that -foo should not be treated the same way as --foo. But I grew up using GNU tools, so I'm biased towards the double-dash syntax. Overall I think this is great. It makes it straightforward to chain option processing across different modules. -- Caleb Epstein caleb dot epstein at gmail dot com

Caleb Epstein wrote:
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'.
Would this only be if "f" is a registered option, or even if it is unregistered? I'd think in the unregistered case you'd end up with -f and two -o's as in the -cd case above.
In the -cd case above we don't have a third letter and '-c' is registered. For -foo case where '-f' is not registered we can treat it either as (-f, "oo") or as (-f,) (-o,) (-o,) I still prefer the first variant, because in this case, if some later code knows -f, it will get the value without problems. If we split -foo into three options without even knowing what's -f, it might be problematic to get (-f, "oo") later.
Whichever the case, I agree that -foo should not be treated the same way as --foo. But I grew up using GNU tools, so I'm biased towards the double-dash syntax.
Yea, me too.
Overall I think this is great. It makes it straightforward to chain option processing across different modules.
I think different modules scenario should be supported already. Each module can provide its own options_description, which can be then combined into a single options_description object used for parsing. Every module can then use the 'variables_map' object to get its parameters. - Volodya

On Fri, 2005-05-06 at 12:06 +0400, Vladimir Prus wrote:
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.
Sure, no problem. I have worked around it for now by using two config files :-(. The use case is I have a config file with some fixed known options and a count field to tell me how may repeating groups are in the file. So I need to read the count option so that I can build the option description for the repeating groups. /ikh _______________________________________________________________________ This email has been scanned for all known viruses by the MessageLabs Email Security System. _______________________________________________________________________
participants (3)
-
Caleb Epstein
-
Iain K. Hanson
-
Vladimir Prus