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:
2022-05-01 20:36:24 -04:00
parent d22679585a
commit 3742c44c40
3 changed files with 44 additions and 2 deletions

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