Have a problem with using additional parser feature:
I want to allow user to use double dashes for short options, so user will
use "-h" or "--h".
But using additional parser the code throws an error about syntax. It seems
there is a bug in additional parser wrapper - in case then my option has no
parameters defined and declared in description it adds an empty value to the
vector of values when additional paser returns pair of strings.
Perhaps there is another way to get what I want, please let me know how to
do it?
Here is an example that illustrates the problem:
#define BOOST_WHATEVER_DYN_LINK
#define BOOST_LIB_DIAGNOSTIC
#include
#include
#include
#include
#include
#include
using namespace boost::program_options;
#include <string>
#include <vector>
using namespace std;
pair parserDashDashShort(const string& s)
{
string str = s.substr( 0, s.find('=') );
if( str.length()==3 && str[0]=='-' && str[1]=='-' && str[2]<='z' &&
str[2]>='a')
{
string val = s.substr(str.length());
return make_pair( str.substr(1), val );
}
return make_pair(string(), string());
}
int _tmain(int , _TCHAR* argv[])
{
int style =
command_line_style::allow_short|
command_line_style::allow_dash_for_short |
command_line_style::short_allow_adjacent;
options_description desc;
desc.add_options()
("help,h", "help message")
;
char* args[]={"program.exe", "--h"};
int argc = sizeof( args ) / sizeof( args[0] );
parse_command_line<char>( argc, (char**)args, desc, style,
parserDashDashShort );
return 0;
}