CLI2: Simplify context determination
Simlifies by offloading portion of the logic into the singleton Context class (which has nothing to do with the task context per se, just a implementation singleton).
This commit is contained in:
@@ -922,6 +922,35 @@ int Context::getHeight ()
|
||||
return height;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::string Context::getTaskContext (const std::string& kind, bool fallback /* = true */)
|
||||
{
|
||||
// Detect if any context is set, and bail out if not
|
||||
std::string contextName = config.get ("context");
|
||||
if (! contextName.empty ())
|
||||
debug (format ("Applying context '{1}'", contextName));
|
||||
else
|
||||
{
|
||||
debug ("No context set");
|
||||
return "";
|
||||
}
|
||||
|
||||
// Figure out the context string for this kind (read/write)
|
||||
std::string contextString = config.get ("context." + contextName + "." + kind);
|
||||
if (contextString.empty ())
|
||||
{
|
||||
debug ("Specific " + kind + " context for '" + contextName + "' not defined. ");
|
||||
if (fallback)
|
||||
{
|
||||
debug ("Falling back on generic.");
|
||||
contextString = config.get ("context." + contextName);
|
||||
}
|
||||
}
|
||||
|
||||
debug (format ("Detected context string: {1}", contextString.empty() ? "(empty)" : contextString));
|
||||
return contextString;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Context::color ()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user