mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-11 02:12:17 +02:00
getValue() with default return value
This commit is contained in:
parent
eb8d0fe039
commit
f5fc13cbad
11
src/config.d
11
src/config.d
|
@ -40,6 +40,16 @@ final class Config
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string getValue(string key, string value)
|
||||||
|
{
|
||||||
|
auto p = key in values;
|
||||||
|
if (p) {
|
||||||
|
return *p;
|
||||||
|
} else {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private bool load(string filename)
|
private bool load(string filename)
|
||||||
{
|
{
|
||||||
scope(failure) return false;
|
scope(failure) return false;
|
||||||
|
@ -65,4 +75,5 @@ unittest
|
||||||
auto cfg = new Config("");
|
auto cfg = new Config("");
|
||||||
cfg.load("onedrive.conf");
|
cfg.load("onedrive.conf");
|
||||||
assert(cfg.getValue("sync_dir") == "~/OneDrive");
|
assert(cfg.getValue("sync_dir") == "~/OneDrive");
|
||||||
|
assert(cfg.getValue("empty", "default") == "default");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue