CmdContext: Discard .read/.write suffix when discovering contexts

This commit is contained in:
Tomas Babej
2021-04-03 00:52:16 -04:00
parent 41823c7939
commit c0ded37f91

View File

@@ -32,6 +32,7 @@
#include <Filter.h> #include <Filter.h>
#include <sstream> #include <sstream>
#include <algorithm> #include <algorithm>
#include <set>
#include <format.h> #include <format.h>
#include <shared.h> #include <shared.h>
#include <util.h> #include <util.h>
@@ -109,13 +110,20 @@ std::string CmdContext::joinWords (const std::vector <std::string>& words, unsig
// //
std::vector <std::string> CmdContext::getContexts () std::vector <std::string> CmdContext::getContexts ()
{ {
std::vector <std::string> contexts; std::set <std::string> contexts;
for (auto& name : Context::getContext ().config) for (auto& name : Context::getContext ().config)
if (name.first.substr (0, 8) == "context.") if (name.first.substr (0, 8) == "context.")
contexts.push_back (name.first.substr (8)); {
std::string suffix = name.first.substr (8);
return contexts; if (suffix.find (".") != std::string::npos)
contexts.insert (suffix.substr (0, suffix.find (".")));
else
contexts.insert (suffix);
}
return std::vector (contexts.begin (), contexts.end ());
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////