Make it possible to give the configuration file location as parameter.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 15 Oct 2014 18:44:39 +0000 (20:44 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 15 Oct 2014 18:44:39 +0000 (20:44 +0200)
pom.xml
src/main/java/net/pterodactylus/xdcc/main/Main.java

diff --git a/pom.xml b/pom.xml
index e7a2e79..248c704 100644 (file)
--- a/pom.xml
+++ b/pom.xml
                        <version>4.11</version>
                        <scope>test</scope>
                </dependency>
+               <dependency>
+                       <groupId>com.lexicalscope.jewelcli</groupId>
+                       <artifactId>jewelcli</artifactId>
+                       <version>0.8.3</version>
+               </dependency>
        </dependencies>
 
        <properties>
index 0033247..381c6a5 100644 (file)
@@ -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 <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+        */
+       private interface Parameters {
+
+               @Option(longName = "configuration", description = "The configuration file", defaultValue = "configuration.json")
+               String getConfiguration();
+
+       }
+
 }