Added add (alias for new) and delete.

This commit is contained in:
Jonathan Bernard 2018-05-14 09:28:43 -05:00
parent 20c82ea9ba
commit fcab7a4cc6
3 changed files with 24 additions and 7 deletions

View File

@ -1,6 +1,6 @@
# Package
version = "4.0.0"
version = "4.0.1"
author = "Jonathan Bernard"
description = "Personal issue tracker."
license = "MIT"

View File

@ -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 <summary> [<state>] [options]
pit ( new | add) <summary> [<state>] [options]
pit list [<state>] [options]
pit ( start | done | pending | do-today | todo ) <id>...
pit edit <id>
pit delete <id>...
Options:
@ -245,6 +246,8 @@ Options:
-F, --future Limit to future issues.
-y, --yes Automatically answer "yes" to any prompts.
-C, --config <cfgFile> 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["<state>"]: parseEnum[IssueState]($args["<state>"])
else: TodoToday
@ -302,7 +305,7 @@ Options:
elif args["todo"]: targetState = Todo
for id in @(args["<id>"]):
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["<id>"]):
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()

View File

@ -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]]()