commit c8aa25cd
Add bsic helper program to remove games
Changed files
| M | .vscode/settings.json before |
| M | src/oastat_delete_games.cpp before |
diff --git a/.vscode/settings.json b/.vscode/settings.json
index c87d914..3e15fe3 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -7,5 +7,58 @@
"*/*.tgz": true,
"Makefile": true,
"nbproject": true
+ },
+ "files.associations": {
+ "cctype": "cpp",
+ "clocale": "cpp",
+ "cmath": "cpp",
+ "cstdarg": "cpp",
+ "cstddef": "cpp",
+ "cstdio": "cpp",
+ "cstdlib": "cpp",
+ "cstring": "cpp",
+ "ctime": "cpp",
+ "cwchar": "cpp",
+ "cwctype": "cpp",
+ "array": "cpp",
+ "atomic": "cpp",
+ "strstream": "cpp",
+ "*.tcc": "cpp",
+ "bitset": "cpp",
+ "chrono": "cpp",
+ "cstdint": "cpp",
+ "deque": "cpp",
+ "list": "cpp",
+ "unordered_map": "cpp",
+ "vector": "cpp",
+ "exception": "cpp",
+ "optional": "cpp",
+ "string_view": "cpp",
+ "fstream": "cpp",
+ "functional": "cpp",
+ "initializer_list": "cpp",
+ "iomanip": "cpp",
+ "iosfwd": "cpp",
+ "iostream": "cpp",
+ "istream": "cpp",
+ "limits": "cpp",
+ "memory": "cpp",
+ "ostream": "cpp",
+ "ratio": "cpp",
+ "sstream": "cpp",
+ "stdexcept": "cpp",
+ "streambuf": "cpp",
+ "system_error": "cpp",
+ "thread": "cpp",
+ "cinttypes": "cpp",
+ "type_traits": "cpp",
+ "tuple": "cpp",
+ "typeindex": "cpp",
+ "typeinfo": "cpp",
+ "utility": "cpp",
+ "variant": "cpp",
+ "complex": "cpp",
+ "new": "cpp",
+ "algorithm": "cpp"
}
}
\ No newline at end of file
diff --git a/src/oastat_delete_games.cpp b/src/oastat_delete_games.cpp
index 184200a..9869faa 100644
--- a/src/oastat_delete_games.cpp
+++ b/src/oastat_delete_games.cpp
@@ -21,7 +21,60 @@ https://github.com/sago007/oastat/
===========================================================================
*/
+#include <iostream>
+#include <fstream>
+#include <vector>
+#include <string>
+#include <boost/program_options.hpp>
+#include "db/DbExtra.hpp"
+
int main (int argc, const char* argv[])
{
+ std::string connectstring;
+ std::vector<int> games_to_delete;
+ std::shared_ptr<cppdb::session> session;
+ try {
+ boost::program_options::options_description desc("Allowed options");
+ desc.add_options()
+ ("help,h", "Print basic usage information to stdout and quits")
+ ("dbargs", boost::program_options::value<std::string>(), "Arguments passed to the DB backend")
+ ("delete-game,d", boost::program_options::value<std::vector<int>>(), "Delete game with a given number from the database")
+ ("config,c", boost::program_options::value<std::vector<std::string> >(), "Read a config file with the values. Can be given multiple times")
+ ;
+ 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("config")) {
+ std::vector<std::string> config_filenames = vm["config"].as<std::vector<std::string> >();
+ for ( const std::string& s : config_filenames) {
+ std::ifstream config_file(s);
+ store(parse_config_file(config_file, desc), vm);
+ notify(vm);
+ }
+ }
+ if (vm.count("help")) {
+ std::cout << desc << "\n";
+ return 1;
+ }
+ if (vm.count("dbargs")) {
+ connectstring = vm["dbargs"].as<std::string>();
+ }
+ if (vm.count("delete-game")) {
+ games_to_delete = vm["delete-game"].as<std::vector<int>>();
+ }
+
+ session = std::make_shared<cppdb::session>(connectstring);
+ cppdb::transaction(*session.get());
+ for (int game : games_to_delete) {
+ std::cout << "Deleting " << game << "..." << std::flush;
+ deleteGame(session.get(), game);
+ std::cout << "done!\n";
+ }
+ session->commit();
+
+ } catch (std::exception& e) {
+ std::cerr << "Failed!\n" << e.what() << "\n";
+ return 1;
+ }
return 0;
-}
\ No newline at end of file
+}