Task: Dependencies are exported as a JSON array

- The 'json.depends.array' setting controls whether dedendencies are encoded as
  a JSON array, or comma-separated string.
- The default value is on.
- Both forms are imported.
This commit is contained in:
Paul Beckingham 2015-07-28 21:54:29 -04:00
parent caab26247c
commit 0f4d3c1d60
6 changed files with 46 additions and 0 deletions

View file

@ -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"

View file

@ -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 <std::string> 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;
}

View file

@ -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"