| 182 | |
| 183 | |
| 184 | void MetaLayer::MergeEnvironmentVariables(const ConfigOption& Option, const DefaultValues::Type::StringArrayType& Value) { |
| 185 | // Environment variables need a bit of additional work |
| 186 | // We want to merge the arrays rather than overwrite entirely |
| 187 | auto MetaEnvironment = OptionMap.find(Option); |
| 188 | if (MetaEnvironment == OptionMap.end()) { |
| 189 | // Doesn't exist, just insert |
| 190 | OptionMap.insert_or_assign(Option, Value); |
| 191 | return; |
| 192 | } |
| 193 | |
| 194 | // If an environment variable exists in both current meta and in the incoming layer then the meta layer value is overwritten |
| 195 | fextl::unordered_map<fextl::string, fextl::string> LookupMap; |
| 196 | const auto AddToMap = [&LookupMap](const DefaultValues::Type::StringArrayType& Value) { |
| 197 | for (const auto& EnvVar : Value) { |
| 198 | const auto ItEq = EnvVar.find_first_of('='); |
| 199 | if (ItEq == fextl::string::npos) { |
| 200 | // Broken environment variable |
| 201 | // Skip |
| 202 | continue; |
| 203 | } |
| 204 | auto Key = fextl::string(EnvVar.begin(), EnvVar.begin() + ItEq); |
| 205 | auto Value = fextl::string(EnvVar.begin() + ItEq + 1, EnvVar.end()); |
| 206 | |
| 207 | // Add the key to the map, overwriting whatever previous value was there |
| 208 | LookupMap.insert_or_assign(std::move(Key), std::move(Value)); |
| 209 | } |
| 210 | }; |
| 211 | |
| 212 | AddToMap(std::get<DefaultValues::Type::StringArrayType>(MetaEnvironment->second)); |
| 213 | AddToMap(Value); |
| 214 | |
| 215 | // Now with the two layers merged in the map |
| 216 | // Add all the values to the option |
| 217 | Erase(Option); |
| 218 | for (auto& Val : LookupMap) { |
| 219 | // Set will emplace multiple options in to its list |
| 220 | AppendStrArrayValue(Option, Val.first + "=" + Val.second); |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | void MetaLayer::MergeConfigMap(const LayerOptions& Options) { |
| 225 | // Insert this layer's options, overlaying previous options that exist here |
nothing calls this directly
no test coverage detected