commit 1e389b22
Now uses boost_program_options. Adds an extra dependency and arguments must now be given with -- in front
Changed files
| M | src/Makefile before |
| M | src/oastat.cpp before |
diff --git a/src/Makefile b/src/Makefile
index da1f4ec..b4feba6 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,7 +1,7 @@
#This is the makefile
USEDBIXX=1
-BASE_LIBS=-lgcrypt
+BASE_LIBS=-lgcrypt -lboost_program_options
BASE_CFLAGS=-c -g -O2 -Wall
O_FILES=build/oastat.o build/oastatstruct.o build/kill2db.o build/init2db.o build/shutdown2db.o build/userinfo2db.o build/disconnect2db.o build/award2db.o build/ctf2db.o build/point2db.o build/ctf1f2db.o build/elimination2db.o build/ctfelim2db.o build/harvester2db.o build/challenge2db.o build/warmup2db.o build/accuracy2db.o
diff --git a/src/oastat.cpp b/src/oastat.cpp
index ceb42ee..36943fc 100644
--- a/src/oastat.cpp
+++ b/src/oastat.cpp
@@ -31,6 +31,7 @@ http://code.google.com/p/oastat/
#include <stdio.h>
#include <list>
#include <boost/shared_ptr.hpp>
+#include <boost/program_options.hpp>
using namespace std;
@@ -157,7 +158,7 @@ static int processStdIn(istream &in_p,vector<shared_ptr<Struct2Db> > &commands)
*/
osslist.clear();
cerr << "oastat: Crashed (NEAR FATAL EXCEPTION) at line: \"" << line << "\"" << endl <<
- "oastat: Error is: " << e2.what() << endl;
+ "oastat: Error is: " << e2.what() << endl;
done = false;
}
} while (!done);
@@ -204,27 +205,44 @@ int main (int argc, const char* argv[])
f % getenv("HOME");
filename = f.str();
////////////
- for (int i=1; i<argc; i++) {
- bool onemore = i+1<argc;
- if (string(argv[i]) == "-dbarg" && onemore ) {
- i++;
- dbargs = string(argv[i]);
- }
- if (string(argv[i]) == "-f" && onemore) {
- i++;
- filename = string(argv[i]);
- }
- if (string(argv[i]) == "-tail") {
- useTail = true;
- }
- if (string(argv[i]) == "-backend" && onemore) {
- i++;
- backend = string(argv[i]);
- }
- if (string(argv[i]) == "--integration-test") {
- doIntegrationTest = true;
- }
+ boost::program_options::options_description desc("Allowed options");
+ desc.add_options()
+ ("help,h", "Print basic usage information to stdout and quits")
+ ("backend", boost::program_options::value<string>(), "The DB backend to use")
+ ("dbargs", boost::program_options::value<string>(), "Arguments passed to the DB backend")
+ ("filename,f", boost::program_options::value<string>(), "Filename to read. Providing a blank string will read from stdin")
+ ("tail", "Use tail on the filename given to read the file")
+ ("integration-test", "Perform integration test")
+ ;
+ boost::program_options::variables_map vm;
+ boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
+ boost::program_options::notify(vm);
+ if (vm.count("help")) {
+ cout << desc << endl;
+ cout << "Examples: " << endl;
+ cout << argv[0] << " -f \"~/.openarena/baseoa/games.log\" --backend \"DbiXX\" --dbarg \"mysql dbname oastat username openarena\"" << endl;
+ cout << argv[0] << " -f \"~/.openarena/baseoa/games.log\" --backend \"DbiXX\" --dbarg \"pgsql dbname oastat username openarena\"" << endl;
+ cout << "tail -f \"~/.openarena/baseoa/games.log\" | "<< argv[0] << " -f \"\" --backend \"Xml\" --dbarg \"outputdir ~/oastat\"" << endl;
+ cout << endl;
+ cout << "Look at http://code.google.com/p/oastat for more help and more details" << endl;
+ return 1;
+ }
+ if (vm.count("backend")) {
+ backend = vm["backend"].as<string>();
}
+ if (vm.count("dbargs")) {
+ dbargs = vm["dbargs"].as<string>();
+ }
+ if (vm.count("filename")) {
+ filename = vm["filename"].as<string>();
+ }
+ if (vm.count("tail")) {
+ useTail = true;
+ }
+ if (vm.count("integration-test")) {
+ doIntegrationTest = true;
+ }
+
try {
shared_ptr<Database> db;