#include "branch_tier.hpp" #include "fmt/core.h" #include "fs_glob.hpp" #include namespace l { static void load_branch_literal(toml::table const &v_, std::vector &branches_) { branches_.emplace_back(v_); } static void load_branch_glob(toml::table const &v_, std::vector &branches_) { toml::table table; std::string pattern; std::vector paths; pattern = v_.at("path").as_string(); fs::glob(pattern,&paths); table = v_; branches_.resize(branches_.size() + paths.size()); for(auto &path : paths) { table["path"] = path; branches_.emplace_back(table); } } static void load_branch_scan(toml::table const &v_, std::vector &branches_) { assert(("not currently supported",0)); } } BranchTier::BranchTier() { } BranchTier::BranchTier(toml::value const &v_) { auto const &branches = toml::find(v_,"branch").as_array(); for(auto const &branch : branches) { bool enabled; std::string type; auto const &table = branch.as_table(); enabled = toml::find_or(branch,"enabled",false); if(!enabled) continue; type = table.at("type").as_string(); if(type == "literal") l::load_branch_literal(table,_branches); else if(type == "glob") l::load_branch_glob(table,_branches); else if(type == "scan") l::load_branch_scan(table,_branches); } }