applyOverrides: add messages after overrides

This commit is contained in:
taiyu 2018-11-15 06:38:25 -08:00 committed by Paul Beckingham
parent 306c628c34
commit 8514071f19

View file

@ -272,36 +272,35 @@ void CLI2::getDataLocation (int argc, const char** argv, Path& data)
// Static method. // Static method.
void CLI2::applyOverrides (int argc, const char** argv) void CLI2::applyOverrides (int argc, const char** argv)
{ {
for (int i = 0; i < argc; ++i) auto& context = Context::getContext ();
auto last = std::find (argv, argv + argc, std::string ("--"));
auto is_override = [] (const std::string& s)
{ {
return s.compare (0, 3, "rc.") == 0;
// Don't process any arguments after a '--' };
std::string raw = argv[i]; auto get_sep = [&] (const std::string& s)
if (raw == "--") {
break; if (is_override (s))
return s.find_first_of (":=", 3);
// Overrides always start with 'rc.' return std::string::npos;
if (raw.length () > 3 && };
raw.substr (0, 3) == "rc.") auto override_settings = [&] (std::string raw)
{ {
auto sep = get_sep (raw);
// Our separator can either be '=' or ':', so try and find both. if (sep == std::string::npos)
auto sep = raw.find ('=', 3); return;
if (sep == std::string::npos) std::string name = raw.substr (3, sep - 3);
sep = raw.find (':', 3); std::string value = raw.substr (sep + 1);
context.config.set (name, value);
// Process our override if well-formed };
if (sep != std::string::npos) auto display_overrides = [&] (std::string raw)
{ {
std::string name = raw.substr (3, sep - 3); if (is_override (raw))
std::string value = raw.substr (sep + 1); context.footnote (format ("Configuration override {1}", raw));
Context::getContext ().config.set (name, value); };
std::for_each (argv, last, override_settings);
if (Context::getContext ().verbose("override")) if (context.verbose ("override"))
Context::getContext ().footnote (format ("Configuration override rc.{1}:{2}", name, value)); std::for_each (argv, last, display_overrides);
}
}
}
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////