Re: [Boost-users] [program_options] multitoken
-----Original Message----- Edward Diener Why not have the parameter as:
"--first=11,12"
instead of trying to create more than one parameter with the same parameter name.
Personally because of the type of solution I suggested, which is probably the way most uses of such a multi-value value parameter would look like, with possibly a different separator than a comma, I do not think a parameter library should have to cater to the same parameter name more than once on the command line.
What about parameters like -I for gcc? Utilities can add -I's to the command line. It would be an added headache to synchronize all these tools to eventually come up with a -I arg1,arg2,...
Sohail Somani wrote:
-----Original Message----- Edward Diener Why not have the parameter as:
"--first=11,12"
instead of trying to create more than one parameter with the same parameter name.
Personally because of the type of solution I suggested, which is probably the way most uses of such a multi-value value parameter would look like, with possibly a different separator than a comma, I do not think a parameter library should have to cater to the same parameter name more than once on the command line.
What about parameters like -I for gcc? Utilities can add -I's to the command line. It would be an added headache to synchronize all these tools to eventually come up with a -I arg1,arg2,...
You are right about that. I think, then, you have to take this up with the creator of the program_options library.
On 2/13/06, Edward Diener
Sohail Somani wrote:
-----Original Message----- Edward Diener Why not have the parameter as:
"--first=11,12"
instead of trying to create more than one parameter with the same parameter name.
Personally because of the type of solution I suggested, which is probably the way most uses of such a multi-value value parameter would look like, with possibly a different separator than a comma, I do not think a parameter library should have to cater to the same parameter name more than once on the command line.
What about parameters like -I for gcc? Utilities can add -I's to the command line. It would be an added headache to synchronize all these tools to eventually come up with a -I arg1,arg2,...
You are right about that. I think, then, you have to take this up with the creator of the program_options library.
I believe this functionality is built right in to the program_options library if you use value< vector<T> > as your value semantic. There is an example of this in the "Getting Started" section of the program_options documentation (http://www.boost.org/doc/html/program_options/tutorial.html). Here is a small snippet of what's in the docs: int opt; po::options_description desc("Allowed options"); desc.add_options() ("help", "produce help message") ("optimization", po::value<int>(&opt)->default_value(10), "optimization level") ("include-path,I", po::value< vector<string> >(), "include path") ("input-file", po::value< vector<string> >(), "input file") ; The tutorial section in the docs isn't 100% clear about what this does, but I'm pretty sure if you have a command-line with (for example) multiple --include-path options, then push_back is called on a vector in the variables_map for each instance of the --include-path option. There is probably a different section in the docs that describes this in detail, but I'm not sure where it is. Hope this helps, Nathan.
Thanks to all for the comments.
I want to allow "--first=11,12" and ""--first=11 --first=12" both, so its
seems I need to do it manually.
Regards,
Alexander.
On 2/14/06, Nathan LeZotte
On 2/13/06, Edward Diener
wrote: Sohail Somani wrote:
-----Original Message----- Edward Diener Why not have the parameter as:
"--first=11,12"
The tutorial section in the docs isn't 100% clear about what this does, but I'm pretty sure if you have a command-line with (for example) multiple --include-path options, then push_back is called on a vector in the variables_map for each instance of the --include-path option. There is probably a different section in the docs that describes this in detail, but I'm not sure where it is.
Hope this helps,
Nathan.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Nathan LeZotte wrote:
I believe this functionality is built right in to the program_options library if you use value< vector<T> > as your value semantic. There is an example of this in the "Getting Started" section of the program_options documentation (http://www.boost.org/doc/html/program_options/tutorial.html). Here is a small snippet of what's in the docs:
int opt; po::options_description desc("Allowed options"); desc.add_options() ("help", "produce help message") ("optimization", po::value<int>(&opt)->default_value(10), "optimization level") ("include-path,I", po::value< vector<string> >(), "include path") ("input-file", po::value< vector<string> >(), "input file") ;
The tutorial section in the docs isn't 100% clear about what this does, but I'm pretty sure if you have a command-line with (for example) multiple --include-path options, then push_back is called on a vector in the variables_map for each instance of the --include-path option.
Hi Nathan, I've just clarified the tutorial to say that std::vector values automatically allow multiple occurences of options. Thanks, Volodya
Hi again
I tried what was in the tutorials at the time and the thing was that, let's say I wanted include paths and files, I would have to write the following:
myCommand -I /path1 -I /path2 -f file1 -f file2
(specifying the option for each file and path so it's pushed back into the vector) That is fine, but if I try the following:
myCommand -I /path1 /path2 -f file1 file2
then the parser didn't recognize the 'file' option and the paths vector<string> had all these elements:
/path1, /path2, -f, file1, file2
That wa not what I expected. In particular, I wanted to do something like myCommand -I /path1/* -f file*, and ran into the previous problem.
Javier
----- Original Message ----
From: Vladimir Prus
I believe this functionality is built right in to the program_options library if you use value< vector<T> > as your value semantic. There is an example of this in the "Getting Started" section of the program_options documentation (http://www.boost.org/doc/html/program_options/tutorial.html). Here is a small snippet of what's in the docs:
int opt; po::options_description desc("Allowed options"); desc.add_options() ("help", "produce help message") ("optimization", po::value<int>(&opt)->default_value(10), "optimization level") ("include-path,I", po::value< vector<string> >(), "include path") ("input-file", po::value< vector<string> >(), "input file") ;
The tutorial section in the docs isn't 100% clear about what this does, but I'm pretty sure if you have a command-line with (for example) multiple --include-path options, then push_back is called on a vector in the variables_map for each instance of the --include-path option.
Hi Nathan, I've just clarified the tutorial to say that std::vector values automatically allow multiple occurences of options. Thanks, Volodya _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Javier Gonzalez wrote:
Hi again
I tried what was in the tutorials at the time and the thing was that, let's say I wanted include paths and files, I would have to write the following:
myCommand -I /path1 -I /path2 -f file1 -f file2
(specifying the option for each file and path so it's pushed back into the vector) That is fine, but if I try the following:
myCommand -I /path1 /path2 -f file1 file2
then the parser didn't recognize the 'file' option and the paths vector<string> had all these elements: /path1, /path2, -f, file1, file2
That wa not what I expected. In particular, I wanted to do something like myCommand -I /path1/* -f file*, and ran into the previous problem.
To begin with, what if you have a file starting with "-I" and your command line is : -f file* -I /path1/* What should happen? - Volodya
participants (6)
-
Alexander Kondratyuk
-
Edward Diener
-
Javier Gonzalez
-
Nathan LeZotte
-
Sohail Somani
-
Vladimir Prus