mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
Switch to resource path type thingies for specifying flux file types, where
appropriate. Much better.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user