@@ -257,39 +257,71 @@ struct PublicSettingsVisitor {
257257 PublicSettings::OptionProperties const & opts,
258258 bool const usingDefault) const
259259 {
260- for (auto & value : values)
260+ // Move command line sink values to appropriate destinations
261+ // Normalization happens later for each destination
262+ if (opts.commandLineSink && opts.filenameMapping .has_value ())
261263 {
262- MRDOCS_TRY (normalizeStringPath (self, name, value, dirs, opts, usingDefault ));
264+ MRDOCS_TRY (normalizeCmdLineSink (self, values, opts));
263265 }
266+ else
267+ {
268+ // General case, normalize each path
269+ for (auto & value : values)
270+ {
271+ MRDOCS_TRY (normalizeStringPath (self, name, value, dirs, opts, usingDefault));
272+ }
273+ }
274+ return {};
275+ }
264276
277+ template <class T >
278+ Expected<void >
279+ normalizeCmdLineSink (
280+ PublicSettings& self,
281+ T& values,
282+ PublicSettings::OptionProperties const & opts) const
283+ {
265284 // Move command line sink values to appropriate destinations
266- if (opts. commandLineSink && opts. filenameMapping . has_value () )
285+ for ( auto & value : values )
267286 {
268- for (auto & value : values)
287+ std::string_view filename = files::getFileName (value);
288+ auto it = opts.filenameMapping ->find (std::string (filename));
289+ if (it == opts.filenameMapping ->end ())
269290 {
270- for (auto const & map = opts.filenameMapping .value ();
271- auto & [from, to] : map)
291+ report::warn (" command line input: unknown destination for filename \" {}\" " , filename);
292+ continue ;
293+ }
294+ // Assign the value to the destination option of the map
295+ std::string const & destOption = it->second ;
296+ bool foundOption = false ;
297+ bool setOption = false ;
298+ self.visit (
299+ [&]<typename U>(
300+ std::string_view const optionName, U& optionValue)
301+ {
302+ if constexpr (std::convertible_to<U, std::string>)
272303 {
273- auto filename = files::getFileName (value);
274- if (filename == from)
304+ if (optionName == destOption)
275305 {
276- self.visit (
277- [&]<typename U>(
278- std::string_view const otherName, U& otherValue)
306+ foundOption = true ;
307+ if (optionValue.empty ())
279308 {
280- if constexpr (std::convertible_to<U, std::string>)
281- {
282- if (otherName == to)
283- {
284- otherValue = value;
285- }
286- }
287- });
309+ optionValue = value;
310+ setOption = true ;
311+ }
288312 }
289313 }
314+ });
315+ if (!foundOption)
316+ {
317+ report::warn (" command line input: cannot find destination option \" {}\" " , destOption);
318+ }
319+ else if (!setOption)
320+ {
321+ report::warn (" command line input: destination option was \" {}\" already set" , destOption);
290322 }
291323 }
292-
324+ values. clear ();
293325 return {};
294326 }
295327
0 commit comments