Make it possible to give the configuration file location as parameter.
[xudocci.git] / src / main / java / net / pterodactylus / xdcc / main / Main.java
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();
+
+       }
+
 }