From c69cbe8bfc4ae3ef82934897810cacd0fd36f44e Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Tue, 28 Sep 2021 21:07:46 -0400 Subject: [PATCH] CmdContext: Remove old-style context during re-definition This makes it easier to migrate from old-style context.=value context definition to new context..read=value and context..write=value variables. --- src/commands/CmdContext.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/commands/CmdContext.cpp b/src/commands/CmdContext.cpp index ca248027d..e1f321e21 100644 --- a/src/commands/CmdContext.cpp +++ b/src/commands/CmdContext.cpp @@ -172,7 +172,8 @@ std::vector CmdContext::getContexts () // void CmdContext::defineContext (const std::vector & words, std::stringstream& out) { - auto confirmation = Context::getContext ().config.getBoolean ("confirmation"); + auto config = Context::getContext ().config; + bool confirmation = config.getBoolean ("confirmation"); if (words.size () > 2) { @@ -230,6 +231,12 @@ void CmdContext::defineContext (const std::vector & words, std::str if (valid_write_context) write_success = CmdConfig::setConfigVariable (name + ".write", value, confirmation); + // Remove old-school context name, if it exists, assuming the read context was defined + if (read_success) + if (config.has (name)) { + CmdConfig::unsetConfigVariable (name, false); + } + if (!read_success and !write_success) throw format ("Context '{1}' not defined.", words[1]); else if (!read_success)