2024-04-02 12:53:17 +00:00
|
|
|
local json = require "cjson"
|
|
|
|
|
|
|
|
local taskwarrior = {}
|
|
|
|
|
2024-04-02 13:03:27 +00:00
|
|
|
--- @param str string
|
|
|
|
--- @return string
|
2024-04-02 12:53:17 +00:00
|
|
|
local function shellescape(str)
|
|
|
|
return "'"..str:gsub([[']], [['"'"']]).."'"
|
|
|
|
end
|
|
|
|
|
2024-04-02 13:03:27 +00:00
|
|
|
|
|
|
|
--- @alias Task table
|
|
|
|
|
|
|
|
--- Imports all tasks from Taskwarrior according to filters if given
|
|
|
|
--- @param ... string Taskwarrior filters as individual strings
|
|
|
|
--- @return Task[] tasks Sequence listing all tasks
|
2024-04-02 12:53:17 +00:00
|
|
|
function taskwarrior.import(...)
|
|
|
|
local filters = {...}
|
|
|
|
for i, filter in ipairs(filters) do
|
|
|
|
filters[i] = shellescape(filter)
|
|
|
|
end
|
|
|
|
return json.decode(io.popen("task "..table.concat(filters, " ").." export"):read("*a"))
|
|
|
|
end
|
|
|
|
|
2024-04-02 13:03:27 +00:00
|
|
|
--- Export tasks back into taskwarrior using the import command
|
|
|
|
--- @param items Task[] Sequence of tasks to import
|
2024-04-02 12:53:17 +00:00
|
|
|
function taskwarrior.export(items)
|
|
|
|
local handle = assert(io.popen("task import"))
|
|
|
|
handle:write(json.encode(items))
|
|
|
|
handle:close()
|
|
|
|
end
|
|
|
|
|
|
|
|
return taskwarrior
|