Simplify conf file argument.
This commit is contained in:
parent
508f1b0219
commit
d76f174eb9
|
@ -1,3 +1,3 @@
|
|||
id = hmci
|
||||
group = biz.nellemann.hmci
|
||||
version = 1.1.5
|
||||
version = 1.1.6
|
||||
|
|
|
@ -32,7 +32,7 @@ import java.util.concurrent.Callable;
|
|||
public class Application implements Callable<Integer> {
|
||||
|
||||
@Option(names = { "-c", "--conf" }, description = "Configuration file [default: '/etc/hmci.toml'].", defaultValue = "/etc/hmci.toml", paramLabel = "<file>")
|
||||
private String configurationFile;
|
||||
private File configurationFile;
|
||||
|
||||
@Option(names = { "-d", "--debug" }, description = "Enable debugging [default: 'false'].")
|
||||
private boolean[] enableDebug = new boolean[0];
|
||||
|
@ -50,9 +50,8 @@ public class Application implements Callable<Integer> {
|
|||
InfluxClient influxClient;
|
||||
List<Thread> threadList = new ArrayList<>();
|
||||
|
||||
File file = new File(configurationFile);
|
||||
if(!file.exists()) {
|
||||
System.err.println("Error - No configuration file found at: " + file.toString());
|
||||
if(!configurationFile.exists()) {
|
||||
System.err.println("Error - No configuration file found at: " + configurationFile.toString());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -66,7 +65,7 @@ public class Application implements Callable<Integer> {
|
|||
}
|
||||
|
||||
try {
|
||||
configuration = new Configuration(configurationFile);
|
||||
configuration = new Configuration(configurationFile.toPath());
|
||||
influxClient = new InfluxClient(configuration.getInflux());
|
||||
influxClient.login();
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ import org.tomlj.TomlTable;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -20,10 +19,9 @@ public final class Configuration {
|
|||
final private InfluxObject influx;
|
||||
final private List<HmcObject> hmcList;
|
||||
|
||||
Configuration(String configurationFile) throws IOException {
|
||||
Configuration(Path configurationFile) throws IOException {
|
||||
|
||||
Path source = Paths.get(configurationFile);
|
||||
TomlParseResult result = Toml.parse(source);
|
||||
TomlParseResult result = Toml.parse(configurationFile);
|
||||
result.errors().forEach(error -> System.err.println(error.toString()));
|
||||
|
||||
if(result.contains("hmci.update")) {
|
||||
|
|
|
@ -2,10 +2,13 @@ package biz.nellemann.hmci
|
|||
|
||||
import spock.lang.Specification
|
||||
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
|
||||
|
||||
class ConfigurationTest extends Specification {
|
||||
|
||||
String testConfigurationFile = new File(getClass().getResource('/hmci.toml').toURI()).absolutePath
|
||||
Path testConfigurationFile = Paths.get(getClass().getResource('/hmci.toml').toURI())
|
||||
|
||||
void "test parsing"() {
|
||||
|
||||
|
|
Loading…
Reference in a new issue