mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Enhancements - shadow file
- Implemented (bug not debugged) the shadow file update. - Added oddly missing (and bypassed) Context::message and Context::footnote methods.
This commit is contained in:
parent
a58aa948b8
commit
ed2ed7c2e2
2 changed files with 53 additions and 55 deletions
106
src/Context.cpp
106
src/Context.cpp
|
@ -26,6 +26,7 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -113,19 +114,18 @@ int Context::run ()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
parse (); // Parse command line.
|
parse (); // Parse command line.
|
||||||
dispatch (); // Dispatch to command handlers.
|
std::cout << dispatch (); // Dispatch to command handlers.
|
||||||
shadow (); // Auto shadow update.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (const std::string& error)
|
catch (const std::string& error)
|
||||||
{
|
{
|
||||||
messages.push_back (error);
|
message (error);
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
messages.push_back (stringtable.get (100, "Unknown error."));
|
message (stringtable.get (100, "Unknown error."));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dump all messages.
|
// Dump all messages.
|
||||||
|
@ -143,7 +143,7 @@ int Context::run ()
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void Context::dispatch ()
|
std::string Context::dispatch ()
|
||||||
{
|
{
|
||||||
bool gcMod = false; // Change occurred by way of gc.
|
bool gcMod = false; // Change occurred by way of gc.
|
||||||
bool cmdMod = false; // Change occurred by way of command type.
|
bool cmdMod = false; // Change occurred by way of command type.
|
||||||
|
@ -199,63 +199,49 @@ void Context::dispatch ()
|
||||||
// Only update the shadow file if such an update was not suppressed (shadow),
|
// Only update the shadow file if such an update was not suppressed (shadow),
|
||||||
// and if an actual change occurred (gcMod || cmdMod).
|
// and if an actual change occurred (gcMod || cmdMod).
|
||||||
// if (shadow && (gcMod || cmdMod))
|
// if (shadow && (gcMod || cmdMod))
|
||||||
// updateShadowFile (tdb);
|
// shadow ();
|
||||||
|
|
||||||
std::cout << out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void Context::shadow ()
|
void Context::shadow ()
|
||||||
{
|
{
|
||||||
/*
|
// Determine if shadow file is enabled.
|
||||||
try
|
std::string shadowFile = expandPath (config.get ("shadow.file"));
|
||||||
|
if (shadowFile != "")
|
||||||
{
|
{
|
||||||
// Determine if shadow file is enabled.
|
std::string oldCurses = config.get ("curses");
|
||||||
std::string shadowFile = expandPath (context.config.get ("shadow.file"));
|
std::string oldColor = config.get ("color");
|
||||||
if (shadowFile != "")
|
config.set ("curses", "off");
|
||||||
|
config.set ("color", "off");
|
||||||
|
|
||||||
|
// Run report. Use shadow.command, using default.command as a fallback
|
||||||
|
// with "list" as a default.
|
||||||
|
std::string command = config.get ("shadow.command",
|
||||||
|
config.get ("default.command", "list"));
|
||||||
|
split (args, command, ' ');
|
||||||
|
|
||||||
|
initialize ();
|
||||||
|
parse ();
|
||||||
|
std::string result = dispatch ();
|
||||||
|
|
||||||
|
std::ofstream out (shadowFile.c_str ());
|
||||||
|
if (out.good ())
|
||||||
{
|
{
|
||||||
std::string oldCurses = context.config.get ("curses");
|
out << result;
|
||||||
std::string oldColor = context.config.get ("color");
|
out.close ();
|
||||||
context.config.set ("curses", "off");
|
|
||||||
context.config.set ("color", "off");
|
|
||||||
|
|
||||||
// Run report. Use shadow.command, using default.command as a fallback
|
|
||||||
// with "list" as a default.
|
|
||||||
std::string command = context.config.get ("shadow.command",
|
|
||||||
context.config.get ("default.command", "list"));
|
|
||||||
std::vector <std::string> args;
|
|
||||||
split (args, command, ' ');
|
|
||||||
std::string result = runTaskCommand (args, tdb);
|
|
||||||
|
|
||||||
std::ofstream out (shadowFile.c_str ());
|
|
||||||
if (out.good ())
|
|
||||||
{
|
|
||||||
out << result;
|
|
||||||
out.close ();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
throw std::string ("Could not write file '") + shadowFile + "'";
|
|
||||||
|
|
||||||
context.config.set ("curses", oldCurses);
|
|
||||||
context.config.set ("color", oldColor);
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
throw std::string ("Could not write file '") + shadowFile + "'";
|
||||||
|
|
||||||
|
config.set ("curses", oldCurses);
|
||||||
|
config.set ("color", oldColor);
|
||||||
|
|
||||||
// Optionally display a notification that the shadow file was updated.
|
// Optionally display a notification that the shadow file was updated.
|
||||||
if (context.config.get (std::string ("shadow.notify"), false))
|
if (config.get (std::string ("shadow.notify"), false))
|
||||||
std::cout << "[Shadow file '" << shadowFile << "' updated]" << std::endl;
|
footnote (std::string ("[Shadow file '") + shadowFile + "' updated]");
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (std::string& error)
|
|
||||||
{
|
|
||||||
std::cerr << error << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
std::cerr << "Unknown error." << std::endl;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
throw std::string ("unimplemented Context::shadow");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -269,7 +255,7 @@ void Context::loadCorrectConfigFile ()
|
||||||
if (access (file.c_str (), F_OK))
|
if (access (file.c_str (), F_OK))
|
||||||
throw std::string ("Could not read configuration file '") + file + "'";
|
throw std::string ("Could not read configuration file '") + file + "'";
|
||||||
|
|
||||||
messages.push_back (std::string ("Using alternate .taskrc file ") + file); // TODO i18n
|
message (std::string ("Using alternate .taskrc file ") + file); // TODO i18n
|
||||||
config.load (file);
|
config.load (file);
|
||||||
|
|
||||||
// No need to handle it again.
|
// No need to handle it again.
|
||||||
|
@ -301,8 +287,8 @@ void Context::loadCorrectConfigFile ()
|
||||||
n.getUntilEOS (value))
|
n.getUntilEOS (value))
|
||||||
{
|
{
|
||||||
config.set (name, value);
|
config.set (name, value);
|
||||||
messages.push_back (std::string ("Configuration override ") + // TODO i18n
|
message (std::string ("Configuration override ") + // TODO i18n
|
||||||
arg->substr (3, std::string::npos));
|
arg->substr (3, std::string::npos));
|
||||||
}
|
}
|
||||||
|
|
||||||
// No need to handle it again.
|
// No need to handle it again.
|
||||||
|
@ -461,3 +447,15 @@ void Context::constructFilter ()
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
void Context::message (const std::string& input)
|
||||||
|
{
|
||||||
|
messages.push_back (input);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
void Context::footnote (const std::string& input)
|
||||||
|
{
|
||||||
|
footnotes.push_back (input);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -47,7 +47,7 @@ public:
|
||||||
void initialize (); // for reinitializing
|
void initialize (); // for reinitializing
|
||||||
int run (); // task classic
|
int run (); // task classic
|
||||||
int interactive (); // task interactive (not implemented)
|
int interactive (); // task interactive (not implemented)
|
||||||
void dispatch (); // command handler dispatch
|
std::string dispatch (); // command handler dispatch
|
||||||
void shadow (); // shadow file update
|
void shadow (); // shadow file update
|
||||||
|
|
||||||
int getWidth (); // determine terminal width
|
int getWidth (); // determine terminal width
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue