Changed the default config location to /etc/dragoon/config.toml; added a CLI option (-c) to specify a different config file.
Some checks failed
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline failed

This commit is contained in:
Gregory Ballantine 2022-07-17 14:04:48 -04:00
parent dad3e6c1cf
commit 2e55876076
4 changed files with 60 additions and 4 deletions

View File

@ -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>

View File

@ -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();

View 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;
}
}

View 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"));
}
}