boost::program_options bug or feature?
        Posted  
        
            by Dmitriy
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Dmitriy
        
        
        
        Published on 2010-04-07T02:38:50Z
        Indexed on 
            2010/04/07
            2:43 UTC
        
        
        Read the original article
        Hit count: 562
        
Very simple example:
#include <string>
#include <boost/program_options.hpp>
namespace po = boost::program_options;
int main(int argc, char* argv[])
{
    po::options_description recipients("Recipient(s)");
    recipients.add_options()
        ("csv",         po::value<std::string>(),     ""  )
        ("csv_name",    po::value<unsigned>(),        ""  )
    ;
    po::options_description cmdline_options;
    cmdline_options.add(recipients);
    po::variables_map vm;
    po::store(po::command_line_parser(argc, argv).options(cmdline_options).run(), vm);
    po::notify(vm);
    return 0;
}
And some tests:
>Test --csv test
in option 'csv_name': invalid option value
>Test --csv_name test
in option 'csv_name': invalid option value
>Test --csv_name 0
>Test --csv text
in option 'csv_name': invalid option value
>Test --csv 0
>Test --csv_name 0
>Test --csv_name 0 --csv text
multiple occurrences
Looks like that boost::program_option threats parameter "csv" as "csv_name".
Is it a feature or bug?
© Stack Overflow or respective owner