From: Stuart Pook <stuart8...@pook.it>
Date: Wed, 04 Jul 2012 17:21:16 +0200
Local: Wed, Jul 4 2012 11:21 am
Subject: [Boost-users] [Program Options] terminate parsing after first positional argument
Hello,
How can I tell Boost Program Options to stop parsing the arguments as soon as it finds a positional argument?
I'd like to be able to parse the argument list "-v chmod -R -v 600 foo" as having one argument for my program (-v) and the rest as a std::vector of std::string (including the -v). In the attached program I have tried 2 different approaches. The first uses multitoken with the arguments "--command date -u -v", it fails because "-u" isn't known.
The second uses collect_unrecognized with "chmod -R -v 600", it doesn't work because -v is interpreted by boost and doesn't end up in the vector.
As someone said back in 2005, perhaps I'm trying to write xargs:
I know that I can ask my users to write
a.out -v -- chmod -R -v 600 foo
but I don't want to do that. I want them to write "a.out -v chmod -R -v 600 foo". The first positional argument should should tell boost to stop processing.
Another slightly different question. If I have a multitoken option that takes doubles how can I get it to accept negative values? If I give my program "--floats 1 8 -4 6" where --floats starts a multitoken option that accepts double, I get an exception saying that "-4" is an unknown option.
thanks
This is what my test program gives me with boost 1.50:
argv: dd --command date -u -v 2nd try
and my program (formatted to fit in 80 characters)
#include <boost/program_options.hpp>
namespace po = boost::program_options;
void print(char const * * b, char const * * e)
}
int main(int argc, char ** argv)
{ { bool verbose; std::vector<std::string> command; po::options_description desc("Allowed options");
char const * args[] = { "dd", "--command", "date", "-u", "-v", 0 };
po::variables_map vm;
std::cout << "2nd try\n";
po::options_description desc("Allowed options");
char const * args[] = { "dd", "chmod", "-R", "-v", "600", 0 };
std::vector<std::string> v = po::collect_unrecognized(
std::cout << "3rd try\n";
po::options_description all("Allowed options");
char const * args[] = { "dd", "--floats", "1", "8", "-4", "6", 0 };
}
_______________________________________________
Boost-users mailing list Boost-us...@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||