我编写了一个程序,接收两个文件列表作为参数:
$ program --to-list-A a b c --to-list-B d e f g
我想允许其他选项出现在命令行的任何位置,并保持这些文件在列表参数的最后一次出现时分组:
$ program --to-list-A a b c --to-list-B d e f --some-option g
两个命令行都应生成包含A
,a
和b
的列表c
以及包含B
的列表d
,{{ 1}},e
和f
。
这可以通过g
来实现吗?到目前为止,我无法在第二种情况下将boost::program_options
添加到g
。这是我使用的测试代码:
B
修改:我希望#include <iostream>
#include <boost/program_options.hpp>
int main( int argc, char** argv )
{
boost::program_options::options_description command_line_options;
command_line_options.add_options()
( "some-option", "boolean option" )
( "to-list-A",
boost::program_options::value< std::vector< std::string > >()
->multitoken() )
( "to-list-B",
boost::program_options::value< std::vector< std::string > >()
->multitoken() );
boost::program_options::positional_options_description positional_options;
positional_options.add( "to-list-A", -1 );
boost::program_options::variables_map arguments;
boost::program_options::store
( boost::program_options::command_line_parser( argc, argv )
.options( command_line_options ).positional( positional_options ).run(),
arguments );
std::cout << "in A:";
if ( arguments.count( "to-list-A" ) != 0 )
for ( const auto& s
: arguments[ "to-list-A" ].as< std::vector< std::string > >() )
std::cout << ' ' << s;
std::cout << '\n';
std::cout << "in B:";
if ( arguments.count( "to-list-B" ) != 0 )
for ( const auto& s
: arguments[ "to-list-B" ].as< std::vector< std::string > >() )
std::cout << ' ' << s;
std::cout << '\n';
return 0;
}
to-list-A' to be implicit for the first files, i.e the following command line should place
b ,
c and
A`:
in