Added ability to load in a TOML file for config
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Gregory Ballantine 2022-05-01 20:36:24 -04:00
parent d22679585a
commit 3742c44c40
3 changed files with 44 additions and 2 deletions

View File

@ -18,6 +18,11 @@
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>org.tomlj</groupId>
<artifactId>tomlj</artifactId>
<version>1.0.0</version>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>

View File

@ -1,5 +1,6 @@
package tech.bitgoblin; package tech.bitgoblin;
import tech.bitgoblin.config.Config;
import tech.bitgoblin.video.Transcoder; import tech.bitgoblin.video.Transcoder;
/** /**
@ -9,9 +10,11 @@ import tech.bitgoblin.video.Transcoder;
public class App { public class App {
public static void main(String[] args) { public static void main(String[] args) {
// read our config file
Config c = new Config("~/dragoon/config.toml");
// create new Transcoder object and start the service // create new Transcoder object and start the service
Transcoder t = new Transcoder("~/dragoon"); //Transcoder t = new Transcoder("~/dragoon");
t.transcode(); //t.transcode();
} }
} }

View File

@ -0,0 +1,34 @@
package tech.bitgoblin.config;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.tomlj.Toml;
import org.tomlj.TomlParseResult;
import tech.bitgoblin.io.IOUtils;
public class Config {
private String configPath;
private TomlParseResult result;
public Config(String path) {
this.configPath = IOUtils.resolveTilda(path);
// parse config file
try {
this.parseConfig();
String value = result.getString("repo");
System.out.println(value);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private void parseConfig() throws IOException {
// parse config file
Path source = Paths.get(this.configPath);
this.result = Toml.parse(source);
this.result.errors().forEach(error -> System.err.println(error.toString()));
}
}