com.xlrit.gears.runner.Main Maven / Gradle / Ivy
The newest version!
package com.xlrit.gears.runner;
import java.io.IOException;
import java.io.InputStream;
import com.google.common.base.Preconditions;
import com.xlrit.gears.runner.driver.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SuppressWarnings({"rawtypes", "unchecked"})
public class Main {
private static final Logger LOG = LoggerFactory.getLogger(Main.class);
public static void main(String[] args) {
// configure JUL to reduce log spam
try (InputStream inputStream = Main.class.getResourceAsStream("/logging.properties");) {
java.util.logging.LogManager.getLogManager().readConfiguration(inputStream);
}
catch (IOException e) {
java.util.logging.Logger.getAnonymousLogger().severe("Could not load default logging.properties file");
java.util.logging.Logger.getAnonymousLogger().severe(e.getMessage());
}
Driver driver = getDriver(args);
Config config = handleArgs(args);
LOG.info("Configured with {}", config);
int failCount = driver.run(config);
System.exit(-failCount);
}
private static Driver getDriver(String[] args) {
return switch (args[0]) {
case "run" -> new RunDriver();
case "load" -> new LoadDriver();
case "export" -> new ExportDriver();
case "eval" -> new EvalDriver();
default -> throw new IllegalArgumentException("Unknown command: " + args[0]);
};
}
private static Config handleArgs(String[] args) {
Preconditions.checkArgument(args.length >= 1, "No command supplied");
Preconditions.checkArgument(args.length >= 2, "No pattern supplied");
LOG.info("Perform command {} with pattern {}", args[0], args[1]);
Config config = switch (args[0]) {
case "run" -> new RunConfig();
case "load" -> new LoadConfig();
case "export" -> new ExportConfig();
case "eval" -> new Config();
default -> throw new IllegalArgumentException("Unknown command: " + args[0]);
};
config.readArgs(args);
return config;
}
}