mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-04 23:12:18 +02:00
alert when no config file is found
This commit is contained in:
parent
53d5d57678
commit
3489827431
16
src/config.d
16
src/config.d
|
@ -6,10 +6,15 @@ struct Config
|
|||
|
||||
this(string[] filenames...)
|
||||
{
|
||||
bool found = false;
|
||||
foreach (filename; filenames) {
|
||||
if (exists(filename)) {
|
||||
found = true;
|
||||
load(filename);
|
||||
}
|
||||
}
|
||||
if (!found) throw new Exception("No config file found");
|
||||
}
|
||||
|
||||
string get(string key)
|
||||
{
|
||||
|
@ -23,7 +28,6 @@ struct Config
|
|||
|
||||
private void load(string filename)
|
||||
{
|
||||
if (exists(filename)) {
|
||||
auto file = File(filename, "r");
|
||||
auto r = regex("(?:^\\s*)(\\w+)(?:\\s*=\\s*\")(.*)(?:\"\\s*$)");
|
||||
foreach (line; file.byLine()) {
|
||||
|
@ -39,10 +43,18 @@ struct Config
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unittest
|
||||
{
|
||||
auto cfg = Config("empty", "onedrive.conf");
|
||||
assert(cfg.get("sync_dir") == "~/OneDrive");
|
||||
}
|
||||
|
||||
unittest
|
||||
{
|
||||
try {
|
||||
auto cfg = Config("empty");
|
||||
assert(0);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue