ブースト v1.45.0 プログラム オプションを使用する Visual Studio 2008 C++ アプリケーションがあります。
次のようなコマンド ライン オプションを解析できるようにしたいと考えています。値 [1, 2, 4, 5, 6, 7] をfoo.exe -x 1,2, 4-7
生成します。std::vector< int >
だから、私はカスタムバリデータを書きました:
typedef std::vector< int > IDList;
void validate( boost::any& v, const std::vector< std::string >& tokens, IDList*, int )
{
// Never gets here
}
int _tmain( int argc, _TCHAR* argv[] )
{
IDList test_case_ids;
po::options_description desc( "Foo options" );
desc.add_options()
("id,x", po::value< IDList >(), "Specify a single ID or a range of IDs as shown in the following command line: foo.exe -x10,12, 15-20")
;
po::variables_map vm;
try
{
po::store( po::parse_command_line( argc, argv, desc ), vm );
po::notify( vm );
}
catch( const std::exception& e)
{
std::cerr << e.what() << std::endl;
std::cout << desc << std::endl;
return 1;
}
return 0;
}
しかし、カスタム バリデータ コードに到達することはありません。私はいつもparse_command_line
メッセージで例外を受け取ります: in option 'id': invalid option value
.
これを希望どおりに機能させるにはどうすればよいですか?
ありがとう、ポールH