@@ -37,46 +37,6 @@ std::optional<std::string_view> ConfigReader::GetDataFromArgs(
37
37
return std::nullopt;
38
38
}
39
39
40
- ParseResult ConfigReader::ParseNodeOptions (
41
- simdjson::ondemand::object* node_options_object) {
42
- auto env_options_map = options_parser::MapEnvOptionsFlagInputType ();
43
- simdjson::ondemand::value ondemand_value;
44
- std::string_view key;
45
-
46
- for (auto field : *node_options_object) {
47
- if (field.unescaped_key ().get (key) || field.value ().get (ondemand_value)) {
48
- return ParseResult::InvalidContent;
49
- }
50
-
51
- // The key needs to match the CLI option
52
- std::string prefix = " --" ;
53
- auto it = env_options_map.find (prefix.append (key));
54
- if (it != env_options_map.end ()) {
55
- // If the option has already been set in the namespace options
56
- // we return an invalid content error
57
- if (unique_namespace_options_.contains (it->first )) {
58
- FPrintF (stderr,
59
- " Option %s is already set in namespace options\n " ,
60
- it->first .c_str ());
61
- return ParseResult::InvalidContent;
62
- }
63
- ParseResult result = ProcessOptionValue (key,
64
- it->first ,
65
- ondemand_value,
66
- it->second ,
67
- &node_options_,
68
- &unique_node_options_);
69
- if (result != ParseResult::Valid) {
70
- return result;
71
- }
72
- } else {
73
- FPrintF (stderr, " Unknown or not allowed option %s\n " , key.data ());
74
- return ParseResult::InvalidContent;
75
- }
76
- }
77
- return ParseResult::Valid;
78
- }
79
-
80
40
ParseResult ConfigReader::ProcessOptionValue (
81
41
const std::string_view& key,
82
42
const std::string& option_name,
@@ -181,6 +141,90 @@ ParseResult ConfigReader::ProcessOptionValue(
181
141
return ParseResult::Valid;
182
142
}
183
143
144
+ ParseResult ConfigReader::ParseNodeOptions (
145
+ simdjson::ondemand::object* node_options_object) {
146
+ auto env_options_map = options_parser::MapEnvOptionsFlagInputType ();
147
+ simdjson::ondemand::value ondemand_value;
148
+ std::string_view key;
149
+
150
+ for (auto field : *node_options_object) {
151
+ if (field.unescaped_key ().get (key) || field.value ().get (ondemand_value)) {
152
+ return ParseResult::InvalidContent;
153
+ }
154
+
155
+ // The key needs to match the CLI option
156
+ std::string prefix = " --" ;
157
+ auto it = env_options_map.find (prefix.append (key));
158
+ if (it != env_options_map.end ()) {
159
+ // If the option has already been set in the namespace options
160
+ // we return an invalid content error
161
+ if (unique_namespace_options_.contains (it->first )) {
162
+ FPrintF (stderr,
163
+ " Option %s is already set in namespace options\n " ,
164
+ it->first .c_str ());
165
+ return ParseResult::InvalidContent;
166
+ }
167
+ ParseResult result = ProcessOptionValue (key,
168
+ it->first ,
169
+ ondemand_value,
170
+ it->second ,
171
+ &node_options_,
172
+ &unique_node_options_);
173
+ if (result != ParseResult::Valid) {
174
+ return result;
175
+ }
176
+ } else {
177
+ FPrintF (stderr, " Unknown or not allowed option %s\n " , key.data ());
178
+ return ParseResult::InvalidContent;
179
+ }
180
+ }
181
+ return ParseResult::Valid;
182
+ }
183
+
184
+ ParseResult ConfigReader::ParseNamespaceOptions (
185
+ simdjson::ondemand::object* options_object,
186
+ const std::string& namespace_name) {
187
+ auto options_map = options_parser::MapOptionsByNamespace (namespace_name);
188
+ simdjson::ondemand::value ondemand_value;
189
+ std::string_view key;
190
+
191
+ for (auto field : *options_object) {
192
+ if (field.unescaped_key ().get (key) || field.value ().get (ondemand_value)) {
193
+ return ParseResult::InvalidContent;
194
+ }
195
+
196
+ // The key needs to match the option for this namespace
197
+ std::string prefix = " --" ;
198
+ auto it = options_map.find (prefix.append (key));
199
+ if (it != options_map.end ()) {
200
+ // If the option has already been set in the nodeOptions
201
+ // we return an invalid content error
202
+ if (unique_node_options_.contains (it->first )) {
203
+ FPrintF (stderr,
204
+ " Option %s is already set in nodeOptions\n " ,
205
+ it->first .c_str ());
206
+ return ParseResult::InvalidContent;
207
+ }
208
+ ParseResult result = ProcessOptionValue (key,
209
+ it->first ,
210
+ ondemand_value,
211
+ it->second ,
212
+ &namespace_options_,
213
+ &unique_namespace_options_);
214
+ if (result != ParseResult::Valid) {
215
+ return result;
216
+ }
217
+ } else {
218
+ FPrintF (stderr,
219
+ " Unknown or not allowed option %s for namespace %s\n " ,
220
+ key.data (),
221
+ namespace_name.c_str ());
222
+ return ParseResult::InvalidContent;
223
+ }
224
+ }
225
+ return ParseResult::Valid;
226
+ }
227
+
184
228
ParseResult ConfigReader::ParseConfig (const std::string_view& config_path) {
185
229
std::string file_content;
186
230
// Read the configuration file
@@ -275,58 +319,10 @@ ParseResult ConfigReader::ParseConfig(const std::string_view& config_path) {
275
319
return ParseResult::Valid;
276
320
}
277
321
278
- ParseResult ConfigReader::ParseNamespaceOptions (
279
- simdjson::ondemand::object* options_object,
280
- const std::string& namespace_name) {
281
- auto options_map = options_parser::MapOptionsByNamespace (namespace_name);
282
- simdjson::ondemand::value ondemand_value;
283
- std::string_view key;
284
-
285
- for (auto field : *options_object) {
286
- if (field.unescaped_key ().get (key) || field.value ().get (ondemand_value)) {
287
- return ParseResult::InvalidContent;
288
- }
289
-
290
- // The key needs to match the option for this namespace
291
- std::string prefix = " --" ;
292
- auto it = options_map.find (prefix.append (key));
293
- if (it != options_map.end ()) {
294
- // If the option has already been set in the nodeOptions
295
- // we return an invalid content error
296
- if (unique_node_options_.contains (it->first )) {
297
- FPrintF (stderr,
298
- " Option %s is already set in nodeOptions\n " ,
299
- it->first .c_str ());
300
- return ParseResult::InvalidContent;
301
- }
302
- ParseResult result = ProcessOptionValue (key,
303
- it->first ,
304
- ondemand_value,
305
- it->second ,
306
- &namespace_options_,
307
- &unique_namespace_options_);
308
- if (result != ParseResult::Valid) {
309
- return result;
310
- }
311
- } else {
312
- FPrintF (stderr,
313
- " Unknown or not allowed option %s for namespace %s\n " ,
314
- key.data (),
315
- namespace_name.c_str ());
316
- return ParseResult::InvalidContent;
317
- }
318
- }
319
- return ParseResult::Valid;
320
- }
321
-
322
322
std::string ConfigReader::AssignNodeOptions () {
323
323
std::string acc = " " ;
324
324
const size_t total_options = node_options_.size () + namespace_options_.size ();
325
325
acc.reserve (total_options * 2 );
326
- // In order to guarantee the order of the options, we need to iterate
327
- // through the node_options_ first, then the namespace_options_
328
- // This is needed in order to avoid breaking changes while introducing
329
- // config namespaces
330
326
for (size_t i = 0 ; i < node_options_.size (); ++i) {
331
327
acc += " " + node_options_[i];
332
328
}
0 commit comments