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