From: David ‘Bombe’ Roden Date: Wed, 15 Oct 2014 18:44:39 +0000 (+0200) Subject: Make it possible to give the configuration file location as parameter. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=eee631ee889a50be9bc498d9aabb7fccf9b8f68e;p=xudocci.git Make it possible to give the configuration file location as parameter. --- diff --git a/pom.xml b/pom.xml index e7a2e79..248c704 100644 --- a/pom.xml +++ b/pom.xml @@ -46,6 +46,11 @@ 4.11 test + + com.lexicalscope.jewelcli + jewelcli + 0.8.3 + diff --git a/src/main/java/net/pterodactylus/xdcc/main/Main.java b/src/main/java/net/pterodactylus/xdcc/main/Main.java index 0033247..381c6a5 100644 --- a/src/main/java/net/pterodactylus/xdcc/main/Main.java +++ b/src/main/java/net/pterodactylus/xdcc/main/Main.java @@ -17,6 +17,8 @@ package net.pterodactylus.xdcc.main; +import static com.lexicalscope.jewel.cli.CliFactory.parseArguments; + import java.io.File; import java.io.InputStreamReader; import java.io.OutputStreamWriter; @@ -42,6 +44,7 @@ import net.pterodactylus.xdcc.ui.stdin.NetworkAdapter; import com.google.common.eventbus.AsyncEventBus; import com.google.common.eventbus.EventBus; +import com.lexicalscope.jewel.cli.Option; import org.codehaus.jackson.map.ObjectMapper; /** @@ -74,8 +77,10 @@ public class Main { Logger.getLogger(Connection.class.getName()).setLevel(Level.INFO); Logger.getLogger(Core.class.getName()).setLevel(Level.INFO); + Parameters parameters = parseArguments(Parameters.class, arguments); + EventBus eventBus = new AsyncEventBus(Executors.newSingleThreadExecutor()); - Configuration configuration = new ObjectMapper().readValue(new File("configuration.json"), Configuration.class); + Configuration configuration = new ObjectMapper().readValue(new File(parameters.getConfiguration()), Configuration.class); Core core = new Core(eventBus, configuration.getTemporaryDirectory(), configuration.getFinalDirectory()); eventBus.register(core); @@ -111,4 +116,16 @@ public class Main { core.start(); } + /** + * Defines the command-line parameters. + * + * @author David ‘Bombe’ Roden + */ + private interface Parameters { + + @Option(longName = "configuration", description = "The configuration file", defaultValue = "configuration.json") + String getConfiguration(); + + } + }