You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.5 KiB

11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
10 months ago
11 months ago
11 months ago
10 months ago
10 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
  1. #include "branch_tier.hpp"
  2. #include "fmt/core.h"
  3. #include "fs_glob.hpp"
  4. #include <cassert>
  5. namespace l
  6. {
  7. static
  8. void
  9. load_branch_literal(toml::table const &v_,
  10. std::vector<Branch2> &branches_)
  11. {
  12. branches_.emplace_back(v_);
  13. }
  14. static
  15. void
  16. load_branch_glob(toml::table const &v_,
  17. std::vector<Branch2> &branches_)
  18. {
  19. toml::table table;
  20. std::string pattern;
  21. std::vector<std::string> paths;
  22. pattern = v_.at("path").as_string();
  23. fs::glob(pattern,&paths);
  24. table = v_;
  25. branches_.resize(branches_.size() + paths.size());
  26. for(auto &path : paths)
  27. {
  28. table["path"] = path;
  29. branches_.emplace_back(table);
  30. }
  31. }
  32. static
  33. void
  34. load_branch_scan(toml::table const &v_,
  35. std::vector<Branch2> &branches_)
  36. {
  37. assert(("not currently supported",0));
  38. }
  39. }
  40. BranchTier::BranchTier()
  41. {
  42. }
  43. BranchTier::BranchTier(toml::value const &v_)
  44. {
  45. auto const &branches = toml::find(v_,"branch").as_array();
  46. for(auto const &branch : branches)
  47. {
  48. bool enabled;
  49. std::string type;
  50. auto const &table = branch.as_table();
  51. enabled = toml::find_or(branch,"enabled",false);
  52. if(!enabled)
  53. continue;
  54. type = table.at("type").as_string();
  55. if(type == "literal")
  56. l::load_branch_literal(table,_branches);
  57. else if(type == "glob")
  58. l::load_branch_glob(table,_branches);
  59. else if(type == "scan")
  60. l::load_branch_scan(table,_branches);
  61. }
  62. }