Properly handle empty config default values

pull/1246/head
Stephen Shelton 4 years ago committed by Jeff Becker
parent dd9ab0f1d5
commit 559610ec94
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -182,12 +182,13 @@ namespace llarp
return addr;
};
conf.defineOption<std::string>("dns", "upstream-dns", true, "", [=](std::string arg) {
m_upstreamDNS.push_back(parseAddr(arg));
});
conf.defineOption<std::string>(
"dns", "upstream-dns", false, true, nonstd::nullopt, [=](std::string arg) {
m_upstreamDNS.push_back(parseAddr(arg));
});
conf.defineOption<std::string>(
"dns", "bind", false, "", [=](std::string arg) { m_bind = parseAddr(arg); });
"dns", "bind", false, nonstd::nullopt, [=](std::string arg) { m_bind = parseAddr(arg); });
}
LinksConfig::LinkInfo

@ -2,6 +2,7 @@
#include <util/str.hpp>
#include <iostream>
#include <memory>
#include <set>
#include <sstream>
@ -122,9 +123,9 @@ namespace llarp
if (parsedValues.size())
return parsedValues[0];
else if (not required and not multiValued)
return defaultValue.value();
return defaultValue;
else
return {};
return nonstd::nullopt;
}
/// Returns the value at the given index.
@ -223,6 +224,7 @@ namespace llarp
{
if (multiValued)
{
std::cout << name << " has " << parsedValues.size() << " parsedValues" << std::endl;
for (const auto& value : parsedValues)
{
acceptor(value);
@ -230,10 +232,16 @@ namespace llarp
}
else
{
std::cout << name << " is NOT multi-valued" << std::endl;
auto maybe = getValue();
assert(maybe.has_value()); // should be guaranteed by our earlier checks
// TODO: avoid copies here if possible
acceptor(maybe.value());
if (maybe.has_value())
{
acceptor(maybe.value());
}
else
{
assert(not defaultValue.has_value()); // maybe should have a value if defaultValue does
}
}
}
}

Loading…
Cancel
Save