Changed the default config location to /etc/dragoon/config.toml; added a CLI option (-c) to specify a different config file.
This commit is contained in:
parent
dad3e6c1cf
commit
2e55876076
5
pom.xml
5
pom.xml
@ -42,6 +42,11 @@
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>commons-cli</groupId>
|
||||
<artifactId>commons-cli</artifactId>
|
||||
<version>1.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.tomlj</groupId>
|
||||
<artifactId>tomlj</artifactId>
|
||||
|
@ -1,5 +1,7 @@
|
||||
package tech.bitgoblin;
|
||||
|
||||
import org.apache.commons.cli.ParseException;
|
||||
import tech.bitgoblin.config.Cmd;
|
||||
import tech.bitgoblin.config.Config;
|
||||
import tech.bitgoblin.transcoder.RunTranscoderTask;
|
||||
import tech.bitgoblin.transcoder.Transcoder;
|
||||
@ -12,13 +14,15 @@ import java.util.Timer;
|
||||
*/
|
||||
public class App {
|
||||
|
||||
private static final String configFile = "~/.config/dragoon.toml";
|
||||
|
||||
private static final int msToMinutes = 60 * 1000;
|
||||
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws ParseException {
|
||||
// parse command-line options
|
||||
Cmd cmd = new Cmd(args);
|
||||
|
||||
// read our config file
|
||||
Config c = new Config(configFile);
|
||||
Config c = new Config(cmd.getConfigPath());
|
||||
|
||||
// create new Transcoder object and start the service
|
||||
Transcoder t = new Transcoder(c);
|
||||
Timer timer = new Timer();
|
||||
|
30
src/main/java/tech/bitgoblin/config/Cmd.java
Normal file
30
src/main/java/tech/bitgoblin/config/Cmd.java
Normal file
@ -0,0 +1,30 @@
|
||||
package tech.bitgoblin.config;
|
||||
|
||||
import org.apache.commons.cli.*;
|
||||
|
||||
public class Cmd {
|
||||
|
||||
private String configPath = "/etc/dragoon/config.toml";
|
||||
|
||||
public Cmd(String[] args) throws ParseException {
|
||||
Options options = new Options();
|
||||
|
||||
Option configPath = new Option("c", "configPath", true, "configuration file path (defaults to /etc/dragoon/config.toml)");
|
||||
configPath.setRequired(false);
|
||||
options.addOption(configPath);
|
||||
|
||||
CommandLineParser parser = new DefaultParser();
|
||||
HelpFormatter formatter = new HelpFormatter();
|
||||
CommandLine cmd = parser.parse(options, args);
|
||||
|
||||
// set the configPath variable if the option was passed to the program
|
||||
if (cmd.hasOption("configPath")) {
|
||||
this.configPath = cmd.getOptionValue("configPath");
|
||||
}
|
||||
}
|
||||
|
||||
public String getConfigPath() {
|
||||
return this.configPath;
|
||||
}
|
||||
|
||||
}
|
17
src/test/java/tech/bitgoblin/config/CmdTest.java
Normal file
17
src/test/java/tech/bitgoblin/config/CmdTest.java
Normal file
@ -0,0 +1,17 @@
|
||||
package tech.bitgoblin.config;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.commons.cli.ParseException;
|
||||
|
||||
public class CmdTest {
|
||||
|
||||
@Test
|
||||
public void shouldDefaultToEtc() throws ParseException {
|
||||
Cmd cmd = new Cmd(new String[]{});
|
||||
assertTrue(cmd.getConfigPath().equals("/etc/dragoon/config.toml"));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user