
Hi all,
I am having troubles with program options. I try to test if at least some
of the available options are passed on the command line, but fail for some
reason using count("option_name"). Here is my code:
int main(int argc, char** argv)
{
string hierarchy;
vector<string> files, directories;
double vertical_shift;
bool show_progress, single_file, single_dir;
int target_EPSG, nb_threads;
po::options_description desc("Allowed options");
desc.add_options()
("help
,h"
, "Produce help message")
("hierarchy ",
po::value<string>(&hierarchy)
, "process a hierarchy)
("file ", po::value (&files) , "process the
specified files")
("directory ", po::value po::variables_map vm;
try
{
po::store(po::parse_command_line(argc, argv, desc), vm);
if (vm.count("help"))
{
cout << desc << "\n";
return 1;
}
po::notify(vm);
}
catch (const po::error &e)
{
cerr << "Exception caught ! --> " << e.what() << endl;
cout << desc << endl;
return 1;
}
if (vm.count("hierarchy"))
{
path input_path(hierarchy);
// DO STUFF
}
else if (vm.count("files"))
{
for(unsigned int i=0;i

Oups. Made à mistake ... However the issue is still there:
if (vm.count("hierarchy"))
{
path input_path(hierarchy);
// DO STUFF
}
else if (vm.count("file"))
{
for(unsigned int i=0;i Hi all, I am having troubles with program options. I try to test if at least some
of the available options are passed on the command line, but fail for some
reason using count("option_name"). Here is my code: int main(int argc, char** argv)
{
string hierarchy;
vector<string> files, directories;
double vertical_shift;
bool show_progress, single_file, single_dir;
int target_EPSG, nb_threads; po::options_description desc("Allowed options");
desc.add_options()
("help
,h"
, "Produce help message")
("hierarchy ",
po::value<string>(&hierarchy)
, "process a hierarchy)
("file ", po::value (&files) , "process the
specified files")
("directory ", po::value po::variables_map vm;
try
{
po::store(po::parse_command_line(argc, argv, desc), vm); if (vm.count("help"))
{
cout << desc << "\n";
return 1;
} po::notify(vm);
}
catch (const po::error &e)
{
cerr << "Exception caught ! --> " << e.what() << endl;
cout << desc << endl;
return 1;
} if (vm.count("hierarchy"))
{
path input_path(hierarchy);
// DO STUFF
}
else if (vm.count("files"))
{
for(unsigned int i=0;i I always fall in the "else". What am I doing wrong? For instance with this command line : ./acute_coordinates_transform
--hierarchy ~/work/data/ À other question: is there à way to specify that 1 of the 3 options is
required (and only 1)? Hope you cloud help. Regards, Olivier

This call I use works for me:
po::command_line_parser(argc, ppargv).options(desc).run()
Don't know if there is an important difference here, or if what you
call is just a wrapper around it, but see if that works for you.
Best,
Dee
On Sat, Feb 2, 2013 at 9:14 PM, Olivier Tournaire
Oups. Made à mistake ... However the issue is still there:
if (vm.count("hierarchy")) { path input_path(hierarchy); // DO STUFF } else if (vm.count("file"))
{ for(unsigned int i=0;i
{ for(unsigned int i=0;i
cout << desc << endl; return 1; }
Le samedi 2 février 2013, Olivier Tournaire a écrit :
Hi all,
I am having troubles with program options. I try to test if at least some of the available options are passed on the command line, but fail for some reason using count("option_name"). Here is my code:
int main(int argc, char** argv) { string hierarchy; vector<string> files, directories; double vertical_shift; bool show_progress, single_file, single_dir; int target_EPSG, nb_threads;
po::options_description desc("Allowed options"); desc.add_options() ("help ,h" , "Produce help message") ("hierarchy ", po::value<string>(&hierarchy) , "process a hierarchy) ("file ", po::value
(&files) , "process the specified files") ("directory ", po::value (&directories) , "process the specified directories"); po::variables_map vm; try { po::store(po::parse_command_line(argc, argv, desc), vm);
if (vm.count("help")) { cout << desc << "\n"; return 1; }
po::notify(vm); } catch (const po::error &e) { cerr << "Exception caught ! --> " << e.what() << endl; cout << desc << endl; return 1; }
if (vm.count("hierarchy")) { path input_path(hierarchy); // DO STUFF } else if (vm.count("files")) { for(unsigned int i=0;i
I always fall in the "else". What am I doing wrong?
For instance with this command line : ./acute_coordinates_transform --hierarchy ~/work/data/
À other question: is there à way to specify that 1 of the 3 options is required (and only 1)?
Hope you cloud help.
Regards,
Olivier
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Thanks Diederick. Did not do the trick.
How I can I access the variables stored in vm ?
Regards,
Olivier
2013/2/2 Diederick C. Niehorster
This call I use works for me: po::command_line_parser(argc, ppargv).options(desc).run()
Don't know if there is an important difference here, or if what you call is just a wrapper around it, but see if that works for you.
Best, Dee
On Sat, Feb 2, 2013 at 9:14 PM, Olivier Tournaire
wrote: Oups. Made à mistake ... However the issue is still there:
if (vm.count("hierarchy")) { path input_path(hierarchy); // DO STUFF } else if (vm.count("file"))
{ for(unsigned int i=0;i
{ for(unsigned int i=0;i
cout << desc << endl; return 1; }
Le samedi 2 février 2013, Olivier Tournaire a écrit :
Hi all,
I am having troubles with program options. I try to test if at least some of the available options are passed on the command line, but fail for some reason using count("option_name"). Here is my code:
int main(int argc, char** argv) { string hierarchy; vector<string> files, directories; double vertical_shift; bool show_progress, single_file, single_dir; int target_EPSG, nb_threads;
po::options_description desc("Allowed options"); desc.add_options() ("help ,h" , "Produce help message") ("hierarchy ", po::value<string>(&hierarchy) , "process a hierarchy) ("file ", po::value
(&files) , "process the specified files") ("directory ", po::value (&directories) , "process the specified directories"); po::variables_map vm; try { po::store(po::parse_command_line(argc, argv, desc), vm);
if (vm.count("help")) { cout << desc << "\n"; return 1; }
po::notify(vm); } catch (const po::error &e) { cerr << "Exception caught ! --> " << e.what() << endl; cout << desc << endl; return 1; }
if (vm.count("hierarchy")) { path input_path(hierarchy); // DO STUFF } else if (vm.count("files")) { for(unsigned int i=0;i
I always fall in the "else". What am I doing wrong?
For instance with this command line : ./acute_coordinates_transform --hierarchy ~/work/data/
À other question: is there à way to specify that 1 of the 3 options is required (and only 1)?
Hope you cloud help.
Regards,
Olivier
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

My bad ... As i'm found of comma alignement, there were spaces in the options values. "file" was "file " ... Le samedi 2 février 2013, Olivier Tournaire a écrit :
Thanks Diederick. Did not do the trick. How I can I access the variables stored in vm ?
Regards,
Olivier
2013/2/2 Diederick C. Niehorster
> This call I use works for me: po::command_line_parser(argc, ppargv).options(desc).run()
Don't know if there is an important difference here, or if what you call is just a wrapper around it, but see if that works for you.
Best, Dee
On Sat, Feb 2, 2013 at 9:14 PM, Olivier Tournaire
wrote: Oups. Made à mistake ... However the issue is still there:
if (vm.count("hierarchy")) { path input_path(hierarchy); // DO STUFF } else if (vm.count("file"))
{ for(unsigned int i=0;i
{ for(unsigned int i=0;i
cout << desc << endl; return 1; }
Le samedi 2 février 2013, Olivier Tournaire a écrit :
Hi all,
I am having troubles with program options. I try to test if at least some of the available options are passed on the command line, but fail for some reason using count("option_name"). Here is my code:
int main(int argc, char** argv) { string hierarchy; vector<string> files, directories; double vertical_shift; bool show_progress, single_file, single_dir; int target_EPSG, nb_threads;
po::options_description desc("Allowed options"); desc.add_options() ("help ,h" , "Produce help message") ("hierarchy ", po::value<string>(&hierarchy) , "process a hierarchy) ("file ", po::value
(&files) , "process the specified files") ("directory ", po::value (&directories) , "process the specified directories"); po::variables_map vm; try { po::store(po::parse_command_line(argc, argv, desc), vm);
if (vm.count("help")) { cout << desc << "\n"; return 1; }
po::notify(vm); } catch (const po::error &e) { cerr << "Exception caught ! --> " << e.what() << endl; cout << desc << endl; return 1; }
if (vm.count("hierarchy")) { path input_path(hierarchy); // DO STUFF } else if (vm.count("files")) { for(unsigned int i=0;i
I always fall in the "else". What am I doing wrong?
For instance with this command line : ./acute_coordinates_transform --hierarchy ~/work/data/
À other question: is there à
participants (2)
-
Diederick C. Niehorster
-
Olivier Tournaire