X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Frhynodge%2Fengine%2FStarter.java;h=7ca75cac51e287b369029179df3192bff2ebf7ef;hb=addfbc56099ebd7609b79a1f9de1a6659d5441e2;hp=05aff64092c8f4ee5421720884b632064b1df26b;hpb=8c6fbacda7fb8a47533b3d9c42653949527dfb0c;p=rhynodge.git diff --git a/src/main/java/net/pterodactylus/rhynodge/engine/Starter.java b/src/main/java/net/pterodactylus/rhynodge/engine/Starter.java index 05aff64..7ca75ca 100644 --- a/src/main/java/net/pterodactylus/rhynodge/engine/Starter.java +++ b/src/main/java/net/pterodactylus/rhynodge/engine/Starter.java @@ -17,15 +17,12 @@ package net.pterodactylus.rhynodge.engine; -import java.io.FileInputStream; import java.io.IOException; import net.pterodactylus.rhynodge.actions.EmailAction; import net.pterodactylus.rhynodge.loader.ChainWatcher; import net.pterodactylus.rhynodge.states.StateManager; - -import com.lexicalscope.jewel.cli.CliFactory; -import com.lexicalscope.jewel.cli.Option; +import net.pterodactylus.util.envopt.Parser; /** * Rhynodge main starter class. @@ -42,57 +39,21 @@ public class Starter { */ public static void main(String... arguments) throws IOException { - /* parse command line. */ - Parameters parameters = CliFactory.parseArguments(Parameters.class, arguments); - Configuration configuration = loadConfiguration(parameters.getConfigurationFile()); + Options options = Parser.fromSystemEnvironment().parseEnvironment(Options::new); /* create the state manager. */ - StateManager stateManager = new StateManager(parameters.getStateDirectory()); + StateManager stateManager = new StateManager(options.stateDirectory); /* create the engine. */ - Engine engine = new Engine(stateManager, createErrorEmailAction(configuration)); + Engine engine = new Engine(stateManager, createErrorEmailAction(options.smtpHostname, options.errorEmailSender, options.errorEmailRecipient)); /* start a watcher. */ - ChainWatcher chainWatcher = new ChainWatcher(engine, parameters.getChainDirectory()); + ChainWatcher chainWatcher = new ChainWatcher(engine, options.chainDirectory); chainWatcher.start(); } - private static Configuration loadConfiguration(String configurationFile) throws IOException { - try (FileInputStream configInputStream = new FileInputStream(configurationFile)) { - return Configuration.from(configInputStream); - } - } - - private static EmailAction createErrorEmailAction(Configuration configuration) { - return new EmailAction(configuration.getSmtpHostname(), configuration.getErrorEmailSender(), configuration.getErrorEmailRecipient()); - } - - /** - * Definition of the command-line parameters. - * - * @author David ‘Bombe’ Roden - */ - private static interface Parameters { - - /** - * Returns the directory to watch for chains. - * - * @return The chain directory - */ - @Option(defaultValue = "chains", longName = "chains", shortName = "c", description = "The directory to watch for chains") - String getChainDirectory(); - - /** - * Returns the directory to store states in. - * - * @return The states directory - */ - @Option(defaultValue = "states", longName = "states", shortName = "s", description = "The directory to store states in") - String getStateDirectory(); - - @Option(defaultValue = "/etc/rhynodge/rhynodge.json", longName = "config", shortName = "C", description = "The name of the configuration file") - String getConfigurationFile(); - + private static EmailAction createErrorEmailAction(String smtpHostname, String errorEmailSender, String errorEmailRecipient) { + return new EmailAction(smtpHostname, errorEmailSender, errorEmailRecipient); } }