Boost logo

Boost :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2005-10-27 04:30:53


Hi Christophe,

> I could not find in the doc whether it is possible to have unknown options
> in the command line and tell the parsers to not worry about them.
> If it is already a feature, then perhaps it should be documented. Otherwise
> I think it could be a nice addition.
> the rationale is that there are framework/libraries out there with there
> own command line options : for example MPI and PETSC

Hmm.. it looks like there's some bad fate with this feature. It was already
present in 1.32, but it was hidden deep inside private interfaces, and so not
usable. For 1.33, I did some refactoring to fix this but looking again, it
looks like it's still not usable, because I privately derive from the class
implementing the relevant method :-(

I've now fixes that, added a test, and even a documentation. It's in CVS HEAD,
and I'll merge it to 1.33.1 branch soon.

Here's the extract from the documentation:

        Allowing unknown options

    Usually, the library throws an exception on unknown option names. This
    behaviour can be changed. For example, only some part of your application
    uses Program_options, and you wish to pass unrecognized options to another
    part of your program, or even another application.

    To allows unregistered options on the command line, you need to use the
    basic_command_line_parser class for parsing (not parse_command_line) and
    call the allow_unregistered method of that class:

    parsed_options parsed =
        command_line_parser(argv, argc).options(desc).
                allow_unregistered().run();
      

    For each token that looks like an option, but does not have a known name,
    an instance of basic_option will be added to the result. The string_key
    and value fields of the instance will contain results of syntactic parsing
    of the token, the unregistered field will be set to true, and the
    original_tokens field will contain the token as it appeared on the command
    line.

     If you want to pass the unrecognized options further, the
     collect_unrecognized function can be used. The function will collect
     original tokens for all unrecognized values, and optionally, all found
     positional options. Say, if your code handles a few options, but does not
     handles positional options at all, you can use the function like this:

     vector<string> to_pass_further = collect_arguments(parsed.option,
     include_positional);
     
- Volodya


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