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; return addr;
}; };
conf.defineOption<std::string>("dns", "upstream-dns", true, "", [=](std::string arg) { conf.defineOption<std::string>(
m_upstreamDNS.push_back(parseAddr(arg)); "dns", "upstream-dns", false, true, nonstd::nullopt, [=](std::string arg) {
}); m_upstreamDNS.push_back(parseAddr(arg));
});
conf.defineOption<std::string>( 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 LinksConfig::LinkInfo

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

Loading…
Cancel
Save