From eee631ee889a50be9bc498d9aabb7fccf9b8f68e Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 15 Oct 2014 20:44:39 +0200 Subject: [PATCH] Make it possible to give the configuration file location as parameter. --- pom.xml | 5 +++++ src/main/java/net/pterodactylus/xdcc/main/Main.java | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) 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(); + + } + } -- 2.7.4