From fcab7a4cc624915a124e5fad1c1a8a04fcb3c869 Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Mon, 14 May 2018 09:28:43 -0500 Subject: [PATCH] Added `add` (alias for `new`) and `delete`. --- pit.nimble | 2 +- src/pit.nim | 25 ++++++++++++++++++++----- src/pit/private/libpit.nim | 4 +++- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/pit.nimble b/pit.nimble index bf17eea..0b6e83d 100644 --- a/pit.nimble +++ b/pit.nimble @@ -1,6 +1,6 @@ # Package -version = "4.0.0" +version = "4.0.1" author = "Jonathan Bernard" description = "Personal issue tracker." license = "MIT" diff --git a/src/pit.nim b/src/pit.nim index 2ff92f9..de4ddd6 100644 --- a/src/pit.nim +++ b/src/pit.nim @@ -5,7 +5,7 @@ import cliutils, docopt, json, logging, options, os, ospaths, sequtils, tables, terminal, times, unicode, uuids -import strutils except capitalize +import strutils except capitalize, toUpper, toLower import pit/private/libpit export libpit @@ -225,10 +225,11 @@ when isMainModule: try: let doc = """ Usage: - pit new [] [options] + pit ( new | add) [] [options] pit list [] [options] pit ( start | done | pending | do-today | todo ) ... pit edit + pit delete ... Options: @@ -245,6 +246,8 @@ Options: -F, --future Limit to future issues. + -y, --yes Automatically answer "yes" to any prompts. + -C, --config Location of the config file (defaults to $HOME/.pitrc) -E, --echo-args Echo arguments (for debug purposes). @@ -258,7 +261,7 @@ Options: logging.addHandler(newConsoleLogger()) # Parse arguments - let args = docopt(doc, version = "pit 4.0.0") + let args = docopt(doc, version = "pit 4.0.1") if args["--echo-args"]: stderr.writeLine($args) @@ -269,7 +272,7 @@ Options: let ctx = initContext(args) ## Actual command runners - if args["new"]: + if args["new"] or args["add"]: let state = if args[""]: parseEnum[IssueState]($args[""]) else: TodoToday @@ -302,7 +305,7 @@ Options: elif args["todo"]: targetState = Todo for id in @(args[""]): - ctx.tasksDir.moveIssue(ctx.tasksDir.loadIssueById(id), targetState) + ctx.tasksDir.loadIssueById(id).changeState(ctx.tasksDir, targetState) if ctx.triggerPtk: if targetState == Current: @@ -313,6 +316,18 @@ Options: discard execShellCmd(cmd) elif targetState == Done: discard execShellCmd("ptk stop") + elif args["delete"]: + for id in @(args[""]): + + let issue = ctx.tasksDir.loadIssueById(id) + + if not args["--yes"]: + stderr.write("Delete '" & issue.summary & "' (y/n)? ") + if not "yes".startsWith(stdin.readLine.toLower): + continue + + issue.delete + elif args["list"]: let filter = initFilter() diff --git a/src/pit/private/libpit.nim b/src/pit/private/libpit.nim index b4565cc..feb331b 100644 --- a/src/pit/private/libpit.nim +++ b/src/pit/private/libpit.nim @@ -160,11 +160,13 @@ proc loadIssues*(path: string): seq[Issue] = if extractFilename(path).match(ISSUE_FILE_PATTERN).isSome(): result.add(loadIssue(path)) -proc moveIssue*(tasksDir: string, issue: Issue, newState: IssueState) = +proc changeState*(issue: Issue, tasksDir: string, newState: IssueState) = removeFile(issue.filepath) if newState == Done: issue.setDateTime("completed", getTime().local) tasksDir.store(issue, newState) +proc delete*(issue: Issue) = removeFile(issue.filepath) + ## Utilities for working with issue collections. proc groupBy*(issues: seq[Issue], propertyKey: string): TableRef[string, seq[Issue]] = result = newTable[string, seq[Issue]]()