Skip to content

Commit

Permalink
Factor out sequence config parsing into a function
Browse files Browse the repository at this point in the history
It will be reused in a later commit.
  • Loading branch information
AndrejMitrovic committed Jun 28, 2019
1 parent 8ffc1b5 commit 64a1e2d
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions source/agora/common/Config.d
Original file line number Diff line number Diff line change
Expand Up @@ -193,23 +193,30 @@ private Config parseConfigFileImpl (CommandLine cmdln)

Node root = Loader.fromFile(cmdln.config_path).load();

if (auto node = "network" in root)
enforce(root["network"].type == NodeType.sequence,
"`network` section must be a section");
else
throw new Exception("The 'network' section is mandatory and must specify at least one peer");
string[] parseSequence ( string section )
{
if (auto node = section in root)
enforce(root[section].type == NodeType.sequence,
format("`%s` section must be a sequence", section));
else
throw new Exception(
format("The '%s' section is mandatory and must " ~
"specify at least one item", section));

string[] network;
foreach (string address; root["network"])
network ~= address;
string[] result;
foreach (string item; root[section])
result ~= item;

return result;
}

enforce("node" in root, "The 'node' section is required");
enforce("quorum" in root, "The 'quorum' section is required");

Config conf =
{
node : parseNodeConfig(root["node"]),
network : assumeUnique(network),
network : assumeUnique(parseSequence("network")),
quorums : assumeUnique(parseQuorumSection(root["quorum"]))
};

Expand Down

0 comments on commit 64a1e2d

Please sign in to comment.