diff --git a/ptk.nim b/ptk.nim index a9cf4f4..ba4e618 100644 --- a/ptk.nim +++ b/ptk.nim @@ -4,7 +4,7 @@ ## Simple time keeping CLI import algorithm, docopt, json, langutils, logging, os, nre, sequtils, - strutils, tempfile, terminal, times, timeutils, uuids + sets, strutils, tempfile, terminal, times, timeutils, uuids import ptkutil @@ -296,6 +296,7 @@ Usage: ptk add [options] ptk add [options] ptk amend [options] [] + ptk merge [...] ptk stop [options] ptk continue ptk delete @@ -332,7 +333,7 @@ Options: let now = getLocalTime(getTime()) # Parse arguments - let args = docopt(doc, version = "ptk 0.5.0") + let args = docopt(doc, version = "ptk 0.6.0") if args["--echo-args"]: echo $args @@ -378,6 +379,30 @@ Options: if args["init"]: doInit(foldl(timelineLocations, if len(a) > 0: a else: b)) + elif args["merge"]: + + let filesToMerge = args[""] + let timelines = filesToMerge.mapIt(loadTimeline(it)) + + let names = timelines.mapIt(it.name).toSet + let mergedName = sequtils.toSeq(names.items).foldl(a & " + " & b) + var merged: Timeline = ( + name: mergedName, + marks: @[]) + + for timeline in timelines: + for mark in timeline.marks: + var existingMarkIdx = merged.marks.findById($mark.id) + if existingMarkIdx >= 0: + if merged.marks[existingMarkIdx].summary != mark.summary: + merged.marks[existingMarkIdx].summary &= " | " & mark.summary + if merged.marks[existingMarkIdx].notes != mark.notes: + merged.marks[existingMarkIdx].notes &= "\r\n--------\r\b" & mark.notes + + else: merged.marks.add(mark) + + writeLine(stdout, pretty(%merged)) + else: if not fileExists(timelineLocation): diff --git a/ptk.nimble b/ptk.nimble index 8a58f0c..c911a1d 100644 --- a/ptk.nimble +++ b/ptk.nimble @@ -1,6 +1,6 @@ # Package -version = "0.5.0" +version = "0.6.0" author = "Jonathan Bernard" description = "Personal Time Keeper" license = "MIT"