From f7ecf950742a20dc18d11a87d5c87e5f19d3ab90 Mon Sep 17 00:00:00 2001 From: Yorick van Pelt Date: Wed, 18 Oct 2023 09:46:13 +0200 Subject: [PATCH] Support multiple arguments to sync multiple days --- src/index.ts | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/index.ts b/src/index.ts index 88066d1..0b77abe 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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) + } })()