This commit is contained in:
79
cli/configuration.cpp
Normal file
79
cli/configuration.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
module;
|
||||
|
||||
#include <string>
|
||||
#include <forward_list>
|
||||
|
||||
#include <toml.hpp>
|
||||
|
||||
import katja.database;
|
||||
import katja.repository;
|
||||
|
||||
export module katja.configuration;
|
||||
|
||||
import katja.component;
|
||||
|
||||
export namespace katja
|
||||
{
|
||||
struct repository_configuration
|
||||
{
|
||||
std::string path;
|
||||
};
|
||||
|
||||
class configuration
|
||||
{
|
||||
public:
|
||||
using repositories_t = std::forward_list<std::pair<std::string, repository_configuration>>;
|
||||
|
||||
private:
|
||||
repositories_t repositories;
|
||||
|
||||
public:
|
||||
void add(const std::string& name, repository_configuration&& repository)
|
||||
{
|
||||
this->repositories.emplace_front(name, std::move(repository));
|
||||
}
|
||||
|
||||
repositories_t::iterator begin()
|
||||
{
|
||||
return this->repositories.begin();
|
||||
}
|
||||
|
||||
repositories_t::iterator end()
|
||||
{
|
||||
return this->repositories.end();
|
||||
}
|
||||
|
||||
repositories_t::const_iterator cbegin()
|
||||
{
|
||||
return this->repositories.cbegin();
|
||||
}
|
||||
|
||||
repositories_t::const_iterator cend()
|
||||
{
|
||||
return this->repositories.cend();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
TOML11_DEFINE_CONVERSION_NON_INTRUSIVE(katja::repository_configuration, path);
|
||||
|
||||
export namespace katja
|
||||
{
|
||||
configuration read_configuration()
|
||||
{
|
||||
auto raw_root = toml::parse("katja.toml");
|
||||
configuration result;
|
||||
|
||||
for (const auto& [root_name, root_value] : raw_root.as_table())
|
||||
{
|
||||
auto repository_value = toml::get<repository_configuration>(root_value);
|
||||
result.add(root_name, std::move(repository_value));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user