Config documentation, clarity

pull/1186/head
Stephen Shelton 4 years ago
parent d9340a873e
commit 8352de7bd4
No known key found for this signature in database
GPG Key ID: EE4BADACCE8B631C

@ -18,7 +18,7 @@ ConfigDefinitionBase::ConfigDefinitionBase(std::string section_,
}
Configuration&
Configuration::addDefinition(ConfigDefinition_ptr def)
Configuration::addConfigOption(ConfigDefinition_ptr def)
{
auto sectionItr = m_definitions.find(def->section);
if (sectionItr == m_definitions.end())

@ -133,13 +133,24 @@ namespace llarp
SectionMap m_definitions;
Configuration&
addDefinition(ConfigDefinition_ptr def);
addConfigOption(ConfigDefinition_ptr def);
Configuration&
addConfigValue(string_view section,
string_view name,
string_view value);
string_view name,
string_view value);
/// Get a config value. If the value hasn't been provided but a default has, the default will
/// be returned. If no value and no default is provided, an empty optional will be returned.
///
/// The type T should exactly match that provided by the definition; it is not sufficient for
/// one type to be a valid substitution for the other.
///
/// @param section is the section this value resides in
/// @param name is the name of the value
/// @return an optional providing the configured value, the default, or empty
/// @throws std::invalid_argument if there is no such config option or the wrong type T was
// provided
template<typename T>
nonstd::optional<T> getConfigValue(string_view section, string_view name)
{

@ -62,7 +62,7 @@ TEST_CASE("ConfigDefinition multiple parses test", "[config]")
TEST_CASE("Configuration basic add/get test", "[config]")
{
llarp::Configuration config;
config.addDefinition(std::make_unique<llarp::ConfigDefinition<int>>(
config.addConfigOption(std::make_unique<llarp::ConfigDefinition<int>>(
"router",
"threads",
false,
@ -85,7 +85,7 @@ TEST_CASE("Configuration missing def test", "[config]")
CHECK_THROWS(config.addConfigValue("foo", "bar", "5"));
CHECK_THROWS(config.getConfigValue<int>("foo", "bar") == 5);
config.addDefinition(std::make_unique<llarp::ConfigDefinition<int>>(
config.addConfigOption(std::make_unique<llarp::ConfigDefinition<int>>(
"quux",
"bar",
false,
@ -98,7 +98,7 @@ TEST_CASE("Configuration missing def test", "[config]")
TEST_CASE("Configuration required test", "[config]")
{
llarp::Configuration config;
config.addDefinition(std::make_unique<llarp::ConfigDefinition<int>>(
config.addConfigOption(std::make_unique<llarp::ConfigDefinition<int>>(
"router",
"threads",
true,
@ -115,13 +115,13 @@ TEST_CASE("Configuration required test", "[config]")
TEST_CASE("Configuration section test", "[config]")
{
llarp::Configuration config;
config.addDefinition(std::make_unique<llarp::ConfigDefinition<int>>(
config.addConfigOption(std::make_unique<llarp::ConfigDefinition<int>>(
"foo",
"bar",
true,
false,
1));
config.addDefinition(std::make_unique<llarp::ConfigDefinition<int>>(
config.addConfigOption(std::make_unique<llarp::ConfigDefinition<int>>(
"goo",
"bar",
true,

Loading…
Cancel
Save