c++ - Boost program option having implicit value erroneously aquires value of positional option -


my boost program options application follows.

namespace po = boost::program_options; desc.add_options()       ( "logfile,l" , po::value<std::string>(&logfilename)->implicit_value( "trace.log" ) , "log file name" )     ( "devicetype,d" , po::value<std::string>(&devicename)->required() , "device type" )     ( "inputfile" , po::value<std::string>(&inputfilename)->required() , "input filename" );  po::positional_options_description positionaloptions; positionaloptions.add( "inputfile" , -1 ); 

the problem that, dependent on position, logfile option can erroneously acquire value of inputfile option. in example:

./application.exe -d frobnigator -l /path/to/input/file.xml 

where /path/to/input/file.xml input file, not log file, error message the option '--inputfile' required missing. no such problem happens when logfile option appears first, so

./application.exe -l -d frobnigator /path/to/input/file.xml 

how can force sort of separation between option implicit value , positional option? or there solution problem?

apparently, command line parser has no way distinguish between these 2 cases:

  1. implicit option, followed value, supposed replace predefined implicit value
  2. implicit option, followed (even required) positional parameter

so, blindly decides go case #1. can still mark end of options double-dash - parser input file name:

./application.exe -d frobnigator -l -- /path/to/input/file.xml 

i think logic makes sense because of simplicity, otherwise taxing on users remember positional parameters required , ones aren't.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -