From 28569a643ee277431bf02474eddd95328450b0e2 Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Mon, 14 May 2018 09:53:15 -0500 Subject: [PATCH] Added Dormant state, auto-create task dirs. The Dormant state is for tasks that are still outstanding but not of immediate importance. The main different between Dormant and Todo is that dormant tasks are not listed by default. You must `pit list dormant` to see them. --- pit.nimble | 2 +- src/pit.nim | 12 +++++++++--- src/pitpkg/private/libpit.nim | 7 +++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/pit.nimble b/pit.nimble index 6c19fc3..6c96f4d 100644 --- a/pit.nimble +++ b/pit.nimble @@ -1,6 +1,6 @@ # Package -version = "4.0.2" +version = "4.0.3" author = "Jonathan Bernard" description = "Personal issue tracker." license = "MIT" diff --git a/src/pit.nim b/src/pit.nim index aa4a7a3..e962c77 100644 --- a/src/pit.nim +++ b/src/pit.nim @@ -227,7 +227,7 @@ when isMainModule: Usage: pit ( new | add) [] [options] pit list [] [options] - pit ( start | done | pending | do-today | todo ) ... + pit ( start | done | pending | do-today | todo | suspend ) ... pit edit pit delete ... @@ -261,7 +261,7 @@ Options: logging.addHandler(newConsoleLogger()) # Parse arguments - let args = docopt(doc, version = "pit 4.0.2") + let args = docopt(doc, version = "pit 4.0.3") if args["--echo-args"]: stderr.writeLine($args) @@ -271,6 +271,11 @@ Options: let ctx = initContext(args) + # Create our tasks directory structure if needed + for s in IssueState: + if not existsDir(ctx.tasksDir / $s): + (ctx.tasksDir / $s).createDir + ## Actual command runners if args["new"] or args["add"]: let state = @@ -295,7 +300,7 @@ Options: edit(ctx.tasksDir.loadIssueById(issueId)) elif args["start"] or args["do-today"] or args["done"] or - args["pending"] or args["todo"]: + args["pending"] or args["todo"] or args["suspend"]: var targetState: IssueState if args["done"]: targetState = Done @@ -303,6 +308,7 @@ Options: elif args["pending"]: targetState = Todo elif args["start"]: targetState = Current elif args["todo"]: targetState = Todo + elif args["suspend"]: targetState = Dormant for id in @(args[""]): ctx.tasksDir.loadIssueById(id).changeState(ctx.tasksDir, targetState) diff --git a/src/pitpkg/private/libpit.nim b/src/pitpkg/private/libpit.nim index feb331b..029aab2 100644 --- a/src/pitpkg/private/libpit.nim +++ b/src/pitpkg/private/libpit.nim @@ -15,6 +15,7 @@ type Pending = "pending", Done = "done", Todo = "todo" + Dormant = "dormant" IssueFilter* = ref object properties*: TableRef[string, string] @@ -27,8 +28,9 @@ let ISSUE_FILE_PATTERN = re"[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f proc displayName*(s: IssueState): string = case s of Current: result = "Current" - of Pending: result = "Pending" of Done: result = "Done" + of Dormant: result = "Dormant" + of Pending: result = "Pending" of Todo: result = "Todo" of TodoToday: result = "Todo" @@ -161,9 +163,10 @@ proc loadIssues*(path: string): seq[Issue] = result.add(loadIssue(path)) proc changeState*(issue: Issue, tasksDir: string, newState: IssueState) = - removeFile(issue.filepath) + let oldFilepath = issue.filepath if newState == Done: issue.setDateTime("completed", getTime().local) tasksDir.store(issue, newState) + removeFile(oldFilepath) proc delete*(issue: Issue) = removeFile(issue.filepath)