diff --git a/ChangeLog b/ChangeLog index d13eca096..508550577 100644 --- a/ChangeLog +++ b/ChangeLog @@ -110,6 +110,8 @@ - Commands that do not accept filters or modifications now generate an error when extra arguments are specified. - Improved zsh support (thanks to Daniel Shahaf). +- Dependencies are exported as a JSON array by default, overridable using + 'rc.json.depends.array=off'. Both forms are imported. ------ current release --------------------------- diff --git a/NEWS b/NEWS index 4c5428053..5d207f387 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,10 @@ New commands in Taskwarrior 2.4.5 New configuration options in Taskwarrior 2.4.5 + - The 'json.depends.array' setting controls whether dependencies are exported + as a JSON array, of a comma-separated string. Default is 'on'. + Both variations are imported. + Newly deprecated features in Taskwarrior 2.4.5 - The '_ids', '_projects', '_tags', '_uuids' helper commands are deprecated, diff --git a/doc/man/taskrc.5.in b/doc/man/taskrc.5.in index b7b6d4700..ef6c4461f 100644 --- a/doc/man/taskrc.5.in +++ b/doc/man/taskrc.5.in @@ -401,6 +401,12 @@ array. With json.array=off, export writes raw JSON objects to STDOUT, one per line. Defaults to on. +.TP +.B json.depends.array=on +Determines whether the export command encodes dependencies as an array of string +UUIDs, or one comma-separated string. +Defaults to on. + .TP .B _forcecolor=no Taskwarrior shuts off color automatically when the output is not sent directly diff --git a/src/Config.cpp b/src/Config.cpp index 694b19285..4123eb3a8 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -107,6 +107,7 @@ std::string Config::_defaults = "expressions=infix # Prefer infix over postfix expressions\n" "dom=on # Support DOM access\n" "json.array=on # Enclose JSON output in [ ]\n" + "json.depends.array=on # Encode dependencies as a JSON array\n" "abbreviation.minimum=2 # Shortest allowed abbreviation\n" "\n" "# Dates\n" diff --git a/src/Task.cpp b/src/Task.cpp index 4ffb8dc5d..9acf86266 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -694,6 +694,18 @@ void Task::parseJSON (const json::object* root_obj) addTag (tag->_data); } + // Dependencies can be exported as a single comma-separated string, or as + // an array of strings. + else if (i.first == "depends" && i.second->type() == json::j_array) + { + json::array* tags = (json::array*)i.second; + for (auto& t : tags->_data) + { + json::string* tag = (json::string*)t; + addDependency (tag->_data); + } + } + // Strings are decoded. else if (type == "string") set (i.first, json::decode (unquoteText (i.second->dump ()))); @@ -887,7 +899,27 @@ std::string Task::composeJSON (bool decorate /*= false*/) const } out << "]"; + ++attributes_written; + } + // Dependencies are an array by default. + else if (i.first == "depends" && + context.config.getBoolean ("json.depends.array")) + { + std::vector deps; + split (deps, i.second, ','); + + out << "\"depends\":["; + + for (auto i = deps.begin (); i != deps.end (); ++i) + { + if (i != deps.begin ()) + out << ","; + + out << "\"" << *i << "\""; + } + + out << "]"; ++attributes_written; } diff --git a/src/commands/CmdShow.cpp b/src/commands/CmdShow.cpp index 1a0868059..b7b43f52c 100644 --- a/src/commands/CmdShow.cpp +++ b/src/commands/CmdShow.cpp @@ -163,6 +163,7 @@ int CmdShow::execute (std::string& output) " journal.time.start.annotation" " journal.time.stop.annotation" " json.array" + " json.depends.array" " list.all.projects" " list.all.tags" " locking"