From 3742c44c40d3afaaaceaea68d2e05f817ce69759 Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Sun, 1 May 2022 20:36:24 -0400 Subject: [PATCH] Added ability to load in a TOML file for config --- pom.xml | 5 +++ src/main/java/tech/bitgoblin/App.java | 7 ++-- .../java/tech/bitgoblin/config/Config.java | 34 +++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 src/main/java/tech/bitgoblin/config/Config.java diff --git a/pom.xml b/pom.xml index 09058a6..45b577d 100644 --- a/pom.xml +++ b/pom.xml @@ -18,6 +18,11 @@ + + org.tomlj + tomlj + 1.0.0 + junit junit diff --git a/src/main/java/tech/bitgoblin/App.java b/src/main/java/tech/bitgoblin/App.java index 11446f4..b0eb866 100644 --- a/src/main/java/tech/bitgoblin/App.java +++ b/src/main/java/tech/bitgoblin/App.java @@ -1,5 +1,6 @@ package tech.bitgoblin; +import tech.bitgoblin.config.Config; import tech.bitgoblin.video.Transcoder; /** @@ -9,9 +10,11 @@ import tech.bitgoblin.video.Transcoder; public class App { 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 - Transcoder t = new Transcoder("~/dragoon"); - t.transcode(); + //Transcoder t = new Transcoder("~/dragoon"); + //t.transcode(); } } diff --git a/src/main/java/tech/bitgoblin/config/Config.java b/src/main/java/tech/bitgoblin/config/Config.java new file mode 100644 index 0000000..4c30551 --- /dev/null +++ b/src/main/java/tech/bitgoblin/config/Config.java @@ -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())); + } + +}