diff --git a/NEWS b/NEWS index 62989f562..4294f9e55 100644 --- a/NEWS +++ b/NEWS @@ -1,23 +1,17 @@ -New Features in taskwarrior 2.2.0 +New Features in taskwarrior 2.3.0 - - Bash autocompletion now works with aliases. - - Virtual tags provide a tag query interface to more complex states. - - Deprecated 'fg' and 'bg' attributes removed. Any residual use of those will - appear as orphaned UDAs. - - Tasks now have a 'modified' attribute, which indicates the last time, if at - all, that they were modified. - - Statistics now report total number of blocked and blocking tasks. + - -New commands in taskwarrior 2.2.0 +New commands in taskwarrior 2.3.0 - - New '_aliases' helper command lists aliases for completion purposes. + - New 'sync' command to synchronize data with a Task Server. -New configuration options in taskwarrior 2.2.0 +New configuration options in taskwarrior 2.3.0 - -Newly deprecated features in taskwarrior 2.2.0 +Newly deprecated features in taskwarrior 2.3.0 - diff --git a/src/commands/CmdDiagnostics.cpp b/src/commands/CmdDiagnostics.cpp index b1dc546ee..40ec7232e 100644 --- a/src/commands/CmdDiagnostics.cpp +++ b/src/commands/CmdDiagnostics.cpp @@ -95,9 +95,6 @@ int CmdDiagnostics::execute (std::string& output) #else STRING_CMD_DIAG_UNKNOWN #endif - << "\n" - << STRING_CMD_DIAG_SERVER << ": " - << context.config.get ("taskd.server") << "\n\n"; // Compiler. diff --git a/src/commands/CmdSync.cpp b/src/commands/CmdSync.cpp index 9b38376b4..b36b39fb4 100644 --- a/src/commands/CmdSync.cpp +++ b/src/commands/CmdSync.cpp @@ -59,7 +59,11 @@ int CmdSync::execute (std::string& output) throw std::string (STRING_CMD_SYNC_NO_SERVER); // Obtain credentials. - std::string credentials = context.config.get ("taskd.credentials"); + std::string credentials_string = context.config.get ("taskd.credentials"); + std::vector credentials; + split (credentials, credentials_string, "/"); + if (credentials.size () != 3) + throw std::string (STRING_CMD_SYNC_BAD_CRED); // Read backlog.data. std::string payload = ""; @@ -70,6 +74,10 @@ int CmdSync::execute (std::string& output) // Send 'sync' + payload. Msg request, response; request.set ("type", "sync"); + request.set ("org", credentials[0]); + request.set ("user", credentials[1]); + request.set ("key", credentials[2]); + // TODO Add the other header fields. request.setPayload (payload); @@ -81,22 +89,29 @@ int CmdSync::execute (std::string& output) { std::cout << "# response:\n" << response.serialize (); - if (response.get ("code") == "200") + std::string code = response.get ("code"); + if (code == "200") { payload = response.getPayload (); std::vector lines; split (lines, payload, '\n'); + std::cout << "# received " << lines.size () << " lines of data\n"; - // TODO Load all tasks. + // Load all tasks. + std::vector all = context.tdb2.all_tasks (); - std::string synch_key; + std::string synch_key = ""; std::vector ::iterator line; for (line = lines.begin (); line != lines.end (); ++line) { if ((*line)[0] == '[') { - // TODO Apply tasks. std::cout << "# task: " << *line << "\n"; + Task from_server (*line); + std::cout << " " << from_server.get ("uuid") + << " " << from_server.get ("description") + << "\n"; + context.tdb2.modify (from_server); } else { @@ -105,19 +120,47 @@ int CmdSync::execute (std::string& output) } } - // TODO Truncate backlog.data. - // TODO Store new synch key. + // Only update everything if there is a new synch_key. No synch_key means + // something horrible happened on the other end of the wire. + if (synch_key != "") + { + // Truncate backlog.data, save new synch_key. + context.tdb2.backlog.clear (); + context.tdb2.backlog.add_line (synch_key + "\n"); - // TODO Commit. + // Commit all changes. + context.tdb2.commit (); + } + } + else if (code == "430") + { + context.error ("Not authorized. Could be incorrect credentials or " + "server account not enabled."); + status = 2; } else { - context.error ("Task Server problem."); + context.error ("Task Server error: " + code + " " + response.get ("status")); status = 2; } - // TODO Display all errors returned. + // Display all errors returned. This is required by the server protocol. + std::string to_be_displayed = response.get ("messages"); + if (to_be_displayed != "") + { + if (context.verbose ("footnote")) + context.footnote (to_be_displayed); + else + context.debug (to_be_displayed); + } } + + // Some kind of low-level error: + // - Server down + // - Wrong address + // - Wrong port + // - Firewall + // - Network error else { context.error ("Could not connect to Task Server."); diff --git a/src/en-US.h b/src/en-US.h index 144ca6a75..785393522 100644 --- a/src/en-US.h +++ b/src/en-US.h @@ -412,6 +412,7 @@ #define STRING_CMD_SHELL_HELP3 "Enter 'quit' (or 'bye', 'exit') to end the session." #define STRING_CMD_SYNC_USAGE "Synchronizes data with the Task Server" #define STRING_CMD_SYNC_NO_SERVER "Task Server is not configured." +#define STRING_CMD_SYNC_BAD_CRED "Task Server credentials malformed." #define STRING_CMD_DIAG_USAGE "Platform, build and environment details" #define STRING_CMD_DIAG_PLATFORM "Platform" #define STRING_CMD_DIAG_UNKNOWN "" @@ -434,7 +435,6 @@ #define STRING_CMD_DIAG_UUID_SCAN "Scanned {1} tasks for duplicate UUIDs:" #define STRING_CMD_DIAG_UUID_DUP "Found duplicate {1}" #define STRING_CMD_DIAG_UUID_NO_DUP "No duplicates found" -#define STRING_CMD_DIAG_SERVER "Task Server" #define STRING_CMD_DIAG_NONE "-none-" #define STRING_CMD_PUSH_USAGE "Pushes the local files to the URL" #define STRING_CMD_PUSH_SAME "Cannot push files when the source and destination are the same."