@@ -148,52 +148,27 @@ ParseResult ConfigReader::ProcessOptionValue(
148
148
return ParseResult::Valid;
149
149
}
150
150
151
- ParseResult ConfigReader::ParseNodeOptions (
152
- simdjson::ondemand::object* node_options_object) {
153
- auto env_options_map = options_parser::MapEnvOptionsFlagInputType ();
154
- simdjson::ondemand::value ondemand_value;
155
- std::string_view key;
156
-
157
- for (auto field : *node_options_object) {
158
- if (field.unescaped_key ().get (key) || field.value ().get (ondemand_value)) {
159
- return ParseResult::InvalidContent;
160
- }
161
-
162
- // The key needs to match the CLI option
163
- std::string prefix = " --" ;
164
- auto it = env_options_map.find (prefix.append (key));
165
- if (it != env_options_map.end ()) {
166
- // If the option has already been set, return an error
167
- if (unique_options_.contains (it->first )) {
168
- FPrintF (stderr, " Option %s is already defined\n " , it->first .c_str ());
169
- return ParseResult::InvalidContent;
170
- }
171
- ParseResult result = ProcessOptionValue (key,
172
- it->first ,
173
- ondemand_value,
174
- it->second ,
175
- &node_options_,
176
- &unique_options_);
177
- if (result != ParseResult::Valid) {
178
- return result;
179
- }
180
- } else {
181
- FPrintF (stderr, " Unknown or not allowed option %s\n " , key.data ());
182
- return ParseResult::InvalidContent;
183
- }
184
- }
185
- return ParseResult::Valid;
186
- }
187
-
188
- ParseResult ConfigReader::ParseNamespaceOptions (
151
+ ParseResult ConfigReader::ParseOptions (
189
152
simdjson::ondemand::object* options_object,
190
153
const std::string& namespace_name) {
191
- // MapOptions could send also options non settable via nodeOptions
192
- auto options_map = options_parser::MapOptionsByNamespace (namespace_name);
193
-
194
- if (!env_options_initialized_) {
195
- env_options_map_ = options_parser::MapEnvOptionsFlagInputType ();
196
- env_options_initialized_ = true ;
154
+ // Determine which options map to use and output vector
155
+ std::unordered_map<std::string, options_parser::OptionType> options_map;
156
+ std::vector<std::string>* output_vector;
157
+
158
+ if (namespace_name == " nodeOptions" ) {
159
+ // Special case for backward compatibility: handle nodeOptions with env
160
+ // options map
161
+ options_map = options_parser::MapEnvOptionsFlagInputType ();
162
+ output_vector = &node_options_;
163
+ } else {
164
+ // Handle other namespaces
165
+ options_map = options_parser::MapOptionsByNamespace (namespace_name);
166
+ output_vector = &namespace_options_;
167
+
168
+ if (!env_options_initialized_) {
169
+ env_options_map_ = options_parser::MapEnvOptionsFlagInputType ();
170
+ env_options_initialized_ = true ;
171
+ }
197
172
}
198
173
199
174
simdjson::ondemand::value ondemand_value;
@@ -204,7 +179,7 @@ ParseResult ConfigReader::ParseNamespaceOptions(
204
179
return ParseResult::InvalidContent;
205
180
}
206
181
207
- // The key needs to match the option for this namespace
182
+ // The key needs to match the CLI option
208
183
std::string prefix = " --" ;
209
184
auto it = options_map.find (prefix.append (key));
210
185
if (it != options_map.end ()) {
@@ -213,12 +188,11 @@ ParseResult ConfigReader::ParseNamespaceOptions(
213
188
FPrintF (stderr, " Option %s is already defined\n " , it->first .c_str ());
214
189
return ParseResult::InvalidContent;
215
190
}
216
- // Process the option for env options
217
191
ParseResult result = ProcessOptionValue (key,
218
192
it->first ,
219
193
ondemand_value,
220
194
it->second ,
221
- &namespace_non_env_options_ ,
195
+ output_vector ,
222
196
&unique_options_);
223
197
if (result != ParseResult::Valid) {
224
198
return result;
@@ -304,20 +278,10 @@ ParseResult ConfigReader::ParseConfig(const std::string_view& config_path) {
304
278
return ParseResult::InvalidContent;
305
279
}
306
280
307
- // Special case for backward compatibility: handle nodeOptions with existing
308
- // method
309
- if (namespace_name == " nodeOptions" ) {
310
- ParseResult result = ParseNodeOptions (&namespace_object);
311
- if (result != ParseResult::Valid) {
312
- return result;
313
- }
314
- } else {
315
- // Process options for this namespace
316
- ParseResult result =
317
- ParseNamespaceOptions (&namespace_object, namespace_name);
318
- if (result != ParseResult::Valid) {
319
- return result;
320
- }
281
+ // Process options for this namespace using the unified method
282
+ ParseResult result = ParseOptions (&namespace_object, namespace_name);
283
+ if (result != ParseResult::Valid) {
284
+ return result;
321
285
}
322
286
}
323
287
@@ -335,7 +299,7 @@ std::string ConfigReader::AssignNodeOptions() {
335
299
}
336
300
337
301
std::vector<std::string> ConfigReader::AssignNodeNonEnvOptions () {
338
- return namespace_non_env_options_ ;
302
+ return namespace_options_ ;
339
303
}
340
304
341
305
size_t ConfigReader::GetFlagsSize () {
0 commit comments