Switch to resource path type thingies for specifying flux file types, where

appropriate. Much better.
This commit is contained in:
David Given
2021-05-18 00:40:16 +02:00
parent b1145f8da3
commit c79feb405c
5 changed files with 42 additions and 9 deletions

View File

@@ -3,6 +3,10 @@
#include "dataspec.h"
#include "fluxsource/fluxsource.h"
#include "lib/config.pb.h"
#include "proto.h"
#include "utils.h"
#include "fmt/format.h"
#include <regex>
static bool ends_with(const std::string& value, const std::string& ending)
{
@@ -35,3 +39,29 @@ std::unique_ptr<FluxSource> FluxSource::create(const FluxSourceProto& config)
return std::unique_ptr<FluxSource>();
}
void FluxSource::updateConfigForFilename(const std::string& filename)
{
FluxSourceProto* f = config.mutable_input()->mutable_flux();
static const std::vector<std::pair<std::regex, std::function<void(const std::string&)>>> formats =
{
{ std::regex("^(.*\\.flux)$"), [&](const auto& s) { f->set_fluxfile(s); }},
{ std::regex("^erase:$"), [&](const auto& s) { f->mutable_erase(); }},
{ std::regex("^kryoflux:(.*)$"), [&](const auto& s) { f->mutable_kryoflux()->set_directory(s); }},
{ std::regex("^testpattern:(.*)"), [&](const auto& s) { f->mutable_test_pattern(); }},
};
for (const auto& it : formats)
{
std::smatch match;
if (std::regex_match(filename, match, it.first))
{
it.second(match[1]);
return;
}
}
Error() << fmt::format("unrecognised flux filename '{}'", filename);
}