Program options negative arguments
If I setup a multitoken option like this: desc.add_options() ("NumberList", po::value<vector<int> >()->multitoken(), "List of numbers.") and then call the program with: ./Program --NumberList 1 2 -3 4 it treats the number "-3" as a new flag so it produces an "unknown option" error. Is there a way to handle this negative argument? Thanks, David
David Doria wrote:
If I setup a multitoken option like this:
desc.add_options() ("NumberList", po::value<vector<int> >()->multitoken(), "List of numbers.")
and then call the program with: ./Program --NumberList 1 2 -3 4
it treats the number "-3" as a new flag so it produces an "unknown option" error. Is there a way to handle this negative argument?
Use a command line style that does not think '-3' is an option. Multitoken options are BAD, exactly because of these ambiguities. - Volodya
Use a command line style that does not think '-3' is an option. Multitoken options are BAD, exactly because of these ambiguities.
- Volodya
Usually what I'm trying to do is input a 3d coordinate. I have tried to do this: vgl_point_3d<double> Point; desc.add_options() ("point,p", po::value<vgl_point_3d<double>
(&Point)->default_value(vgl_point_3d<double>(0.0, 0.0, 0.0)), "set point")
But when I run the program with: ./Test --point 1 2 3 I get: what(): in option 'point': invalid option value '1' (the input operator is properly defined, ie vgl_point_3d<double> P; std::cin >> P; works as expected). This is why I resorted to a multitoken option. The other option I can think of is --x 1 --y 2 --z 3, is that what you are recommending? Thanks, Dave
David Doria wrote:
Use a command line style that does not think '-3' is an option. Multitoken options are BAD, exactly because of these ambiguities.
- Volodya
Usually what I'm trying to do is input a 3d coordinate. I have tried to do this:
vgl_point_3d<double> Point; desc.add_options() ("point,p", po::value<vgl_point_3d<double>
(&Point)->default_value(vgl_point_3d<double>(0.0, 0.0, 0.0)), "set point")
But when I run the program with: ./Test --point 1 2 3
I get: what(): in option 'point': invalid option value '1'
(the input operator is properly defined, ie vgl_point_3d<double> P; std::cin >> P;
works as expected).
This is why I resorted to a multitoken option. The other option I can think of is --x 1 --y 2 --z 3, is that what you are recommending?
Having --point 1,2,3 would seem reasonable -- I assume your point class has already operator>> that will parse some representation? - Volodya
participants (2)
-
David Doria
-
Vladimir Prus