mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-27 19:17:19 +02:00
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:
parent
985aab0541
commit
9a380887ee
3 changed files with 54 additions and 41 deletions
|
@ -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 ()
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue