Files
tlw-database-tool/src/main/java/de/jeyp91/App.java

86 lines
2.9 KiB
Java

package de.jeyp91;
import de.jeyp91.tippliga.*;
import net.sourceforge.argparse4j.ArgumentParsers;
import net.sourceforge.argparse4j.inf.ArgumentParser;
import net.sourceforge.argparse4j.inf.ArgumentParserException;
import net.sourceforge.argparse4j.inf.Namespace;
/**
* Hello world!
*
*/
public class App {
private static String mode;
private static int season;
private static int league;
private static String configFile;
public static void main(String[] args) throws Exception {
initOptions(args);
String sql = "";
switch(mode) {
case "MatchdaysUpdater":
TLWMatchdaysUpdater matchdaysUpdater = new TLWMatchdaysUpdater(season, league, configFile);
sql = matchdaysUpdater.getUpdateSql();
break;
case "MatchesCreatorFootball":
TLWMatchesCreatorFootball creator = new TLWMatchesCreatorFootball(season, league, configFile);
sql = creator.getSQLInsertString();
break;
case "MatchesUpdaterFootball":
TLWMatchesUpdaterFootball updater = new TLWMatchesUpdaterFootball(season, league, configFile);
sql = updater.getUpdateSQL();
break;
case "TeamsUpdater":
TLWTeamsUpdater teamsUpdater = new TLWTeamsUpdater(season, league, configFile);
sql = teamsUpdater.getInsertSQL();
default:
break;
}
if(!StatusHolder.getError()) {
TippligaSQLConnector con = new TippligaSQLConnector();
con.executeQuery(sql);
}
}
private static void initOptions(String[] args) {
ArgumentParser parser = ArgumentParsers.newFor("tlw").build()
.defaultHelp(true)
.description("");
parser.addArgument("-m", "--mode")
.dest("mode")
.choices("MatchdaysUpdater", "MatchesCreatorFootball", "MatchesUpdaterFootball", "TeamsUpdater")
.help("")
.required(true)
.type(String.class);
parser.addArgument("-s", "--season")
.dest("season")
.required(true)
.type(Integer.class);
parser.addArgument("-l", "--league")
.dest("league")
.required(true)
.type(Integer.class);
parser.addArgument("-c", "--configFile")
.dest("configFile")
.required(true)
.type(String.class);
Namespace res = null;
try {
res = parser.parseArgs(args);
} catch (ArgumentParserException e) {
parser.printHelp();
System.exit(1);
}
mode = res.get("mode");
season = res.get("season");
league = res.get("league");
configFile = res.get("configFile");
}
}