Pull command
- Added pull command for cloning databases
This commit is contained in:
@@ -173,7 +173,8 @@ void Cmd::load ()
|
||||
commands.push_back (context.stringtable.get (CMD_UNDO, "undo"));
|
||||
commands.push_back (context.stringtable.get (CMD_VERSION, "version"));
|
||||
commands.push_back (context.stringtable.get (CMD_MERGE, "merge"));
|
||||
commands.push_back (context.stringtable.get (CMD_PUSH, "push"));
|
||||
commands.push_back (context.stringtable.get (CMD_PUSH, "push"));
|
||||
commands.push_back (context.stringtable.get (CMD_PULL, "pull"));
|
||||
|
||||
// Now load the custom reports.
|
||||
std::vector <std::string> all;
|
||||
@@ -277,6 +278,7 @@ bool Cmd::isWriteCommand ()
|
||||
command == context.stringtable.get (CMD_IMPORT, "import") ||
|
||||
command == context.stringtable.get (CMD_LOG, "log") ||
|
||||
command == context.stringtable.get (CMD_PREPEND, "prepend") ||
|
||||
command == context.stringtable.get (CMD_PULL, "pull") ||
|
||||
command == context.stringtable.get (CMD_START, "start") ||
|
||||
command == context.stringtable.get (CMD_STOP, "stop") ||
|
||||
command == context.stringtable.get (CMD_UNDO, "undo"))
|
||||
|
||||
@@ -80,7 +80,6 @@ std::string Config::defaults =
|
||||
"recurrence.indicator=R # What to show as a task recurrence indicator\n"
|
||||
"recurrence.limit=1 # Number of future recurring pending tasks\n"
|
||||
"undo.style=side # Undo style - can be 'side', or 'diff'\n"
|
||||
"merge.autopush=ask # Push database to remote origin after merge: yes, no, ask\n"
|
||||
"\n"
|
||||
"# Dates\n"
|
||||
"dateformat=m/d/Y # Preferred input and display date format\n"
|
||||
@@ -232,6 +231,11 @@ std::string Config::defaults =
|
||||
"fontunderline=yes # Uses underlines rather than -------\n"
|
||||
"shell.prompt=task> # Prompt used by the shell command\n"
|
||||
"\n"
|
||||
"# Merge options\n"
|
||||
"merge.autopush=ask # Push database to remote origin after merge: yes, no, ask\n"
|
||||
"#merge.default.uri=user@host.xz:.task/\n"
|
||||
"#pull.default.uri=rsync://host.xz/task-backup/\n"
|
||||
"\n"
|
||||
"# Import heuristics - alternate names for fields (comma-separated list of names)\n"
|
||||
"#import.synonym.bg=?\n"
|
||||
"#import.synonym.description=?\n"
|
||||
|
||||
@@ -244,6 +244,7 @@ int Context::dispatch (std::string &out)
|
||||
else if (cmd.command == "merge") { tdb.gc ();
|
||||
handleMerge (out); }
|
||||
else if (cmd.command == "push") { handlePush (out); }
|
||||
else if (cmd.command == "pull") { handlePull (out); }
|
||||
else if (cmd.command == "_projects") { rc = handleCompletionProjects (out); }
|
||||
else if (cmd.command == "_tags") { rc = handleCompletionTags (out); }
|
||||
else if (cmd.command == "_commands") { rc = handleCompletionCommands (out); }
|
||||
|
||||
@@ -167,6 +167,8 @@ Hooks::Hooks ()
|
||||
validProgramEvents.push_back ("post-prepend-command");
|
||||
validProgramEvents.push_back ("pre-projects-command");
|
||||
validProgramEvents.push_back ("post-projects-command");
|
||||
validProgramEvents.push_back ("pre-pull-command");
|
||||
validProgramEvents.push_back ("post-pull-command");
|
||||
validProgramEvents.push_back ("pre-push-command");
|
||||
validProgramEvents.push_back ("post-push-command");
|
||||
validProgramEvents.push_back ("pre-shell-command");
|
||||
|
||||
@@ -598,6 +598,20 @@ void handleMerge (std::string& outs)
|
||||
{
|
||||
std::string file = trim (context.task.get ("description"));
|
||||
std::string tmpfile = "";
|
||||
|
||||
if (file.length () == 0)
|
||||
{
|
||||
// get default target from config
|
||||
file = context.config.get ("merge.default.uri");
|
||||
}
|
||||
else
|
||||
{
|
||||
// replace argument with uri from config
|
||||
std::string tmp = context.config.get ("merge." + file + ".uri");
|
||||
|
||||
if (tmp != "")
|
||||
file = tmp;
|
||||
}
|
||||
|
||||
if (file.length () > 0)
|
||||
{
|
||||
@@ -654,6 +668,20 @@ void handlePush (std::string& outs)
|
||||
if (context.hooks.trigger ("pre-push-command"))
|
||||
{
|
||||
std::string file = trim (context.task.get ("description"));
|
||||
|
||||
if (file.length () == 0)
|
||||
{
|
||||
// get default target from config
|
||||
file = context.config.get ("push.default.uri");
|
||||
}
|
||||
else
|
||||
{
|
||||
// replace argument with uri from config
|
||||
std::string tmp = context.config.get ("push." + file + ".uri");
|
||||
|
||||
if (tmp != "")
|
||||
file = tmp;
|
||||
}
|
||||
|
||||
if (file.length () > 0)
|
||||
{
|
||||
@@ -672,6 +700,58 @@ void handlePush (std::string& outs)
|
||||
|
||||
context.hooks.trigger ("post-push-command");
|
||||
}
|
||||
else // TODO : get default target from config file
|
||||
throw std::string ("You must specify a target.");
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void handlePull (std::string& outs)
|
||||
{
|
||||
if (context.hooks.trigger ("pre-pull-command"))
|
||||
{
|
||||
std::string file = trim (context.task.get ("description"));
|
||||
|
||||
if (file.length () == 0)
|
||||
{
|
||||
// get default target from config
|
||||
file = context.config.get ("pull.default.uri");
|
||||
}
|
||||
else
|
||||
{
|
||||
// replace argument with uri from config
|
||||
std::string tmp = context.config.get ("pull." + file + ".uri");
|
||||
|
||||
if (tmp != "")
|
||||
file = tmp;
|
||||
}
|
||||
|
||||
if (file.length () > 0)
|
||||
{
|
||||
Directory location (context.config.get ("data.location"));
|
||||
|
||||
// add *.data to path if necessary
|
||||
if (file.find ("*.data") == std::string::npos)
|
||||
{
|
||||
if (file[file.length()-1] != '/')
|
||||
file += "/";
|
||||
|
||||
file += "*.data";
|
||||
}
|
||||
|
||||
Transport* transport;
|
||||
if ((transport = Transport::getTransport (file)) != NULL )
|
||||
{
|
||||
transport->recv (location.data + "/");
|
||||
delete transport;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::string ("Pull failed");
|
||||
}
|
||||
|
||||
context.hooks.trigger ("post-pull-command");
|
||||
}
|
||||
else // TODO : get default target from config file
|
||||
throw std::string ("You must specify a target.");
|
||||
}
|
||||
|
||||
@@ -100,6 +100,7 @@
|
||||
#define CMD_SHOW 231
|
||||
#define CMD_MERGE 232
|
||||
#define CMD_PUSH 233
|
||||
#define CMD_PULL 234
|
||||
|
||||
// 3xx Attributes
|
||||
#define ATT_PROJECT 300
|
||||
|
||||
@@ -79,6 +79,7 @@ int handleDuplicate (std::string &);
|
||||
void handleUndo ();
|
||||
void handleMerge (std::string&);
|
||||
void handlePush (std::string&);
|
||||
void handlePull (std::string&);
|
||||
#ifdef FEATURE_SHELL
|
||||
void handleShell ();
|
||||
#endif
|
||||
|
||||
@@ -209,7 +209,11 @@ int shortUsage (std::string &outs)
|
||||
|
||||
row = table.addRow ();
|
||||
table.addCell (row, 1, "task push URL");
|
||||
table.addCell (row, 2, "Pushes the local undo.data files to the URL.");
|
||||
table.addCell (row, 2, "Pushes the local *.data files to the URL.");
|
||||
|
||||
row = table.addRow ();
|
||||
table.addCell (row, 1, "task pull URL");
|
||||
table.addCell (row, 2, "Overwrites the local *.data files with those found at the URL.");
|
||||
|
||||
row = table.addRow ();
|
||||
table.addCell (row, 1, "task export.ical");
|
||||
|
||||
Reference in New Issue
Block a user