Support multiple arguments to sync multiple days

main
Yorick van Pelt 2023-10-18 09:46:13 +02:00
parent f1cc532f3d
commit f7ecf95074
Signed by: yorick
GPG Key ID: D8D3CC6D951384DE
1 changed files with 15 additions and 11 deletions

View File

@ -99,24 +99,28 @@ async function apply_tasks_for_range(workspace: Workspace, interval: Interval, w
void (async function () {
const config = await inferConfig()
const interval = dateToInterval(process.argv.length > 2 ? process.argv[2] : 'today')
const args = process.argv.length > 2 ? process.argv.slice(2) : ["today"]
const marvin = new Marvin(Marvin.parseCredentials(config.marvin), config.marvinDB + "marvin")
const tasks = await (marvin.root.category('Datakami').then(datakami => datakami.tasksOverlapping(interval)))
const toggl = new Toggl(config.toggl)
const workspaces = await toggl.workspaces()
if (workspaces.length !== 1) throw new Error("not sure which workspace to use")
for (const arg of args) {
const interval = dateToInterval(arg)
const tasks = await (marvin.root.category('Datakami').then(datakami => datakami.tasksOverlapping(interval)))
const res_tasks: TogglTE[] = []
for (const task of tasks)
for (const task_interval of task.timesInInterval(interval))
res_tasks.push({
description: `${task.title}`,
start: toRFC3339(task_interval.start),
stop: toRFC3339(task_interval.end)
})
const res_tasks: TogglTE[] = []
for (const task of tasks)
for (const task_interval of task.timesInInterval(interval))
res_tasks.push({
description: `${task.title}`,
start: toRFC3339(task_interval.start),
stop: toRFC3339(task_interval.end)
})
await apply_tasks_for_range(workspaces[0], interval, res_tasks)
await apply_tasks_for_range(workspaces[0], interval, res_tasks)
}
})()