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 # Package
version = "4.0.0" version = "4.0.1"
author = "Jonathan Bernard" author = "Jonathan Bernard"
description = "Personal issue tracker." description = "Personal issue tracker."
license = "MIT" license = "MIT"

View File

@ -5,7 +5,7 @@
import cliutils, docopt, json, logging, options, os, ospaths, sequtils, import cliutils, docopt, json, logging, options, os, ospaths, sequtils,
tables, terminal, times, unicode, uuids tables, terminal, times, unicode, uuids
import strutils except capitalize import strutils except capitalize, toUpper, toLower
import pit/private/libpit import pit/private/libpit
export libpit export libpit
@ -225,10 +225,11 @@ when isMainModule:
try: try:
let doc = """ let doc = """
Usage: Usage:
pit new <summary> [<state>] [options] pit ( new | add) <summary> [<state>] [options]
pit list [<state>] [options] pit list [<state>] [options]
pit ( start | done | pending | do-today | todo ) <id>... pit ( start | done | pending | do-today | todo ) <id>...
pit edit <id> pit edit <id>
pit delete <id>...
Options: Options:
@ -245,6 +246,8 @@ Options:
-F, --future Limit to future issues. -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) -C, --config <cfgFile> Location of the config file (defaults to $HOME/.pitrc)
-E, --echo-args Echo arguments (for debug purposes). -E, --echo-args Echo arguments (for debug purposes).
@ -258,7 +261,7 @@ Options:
logging.addHandler(newConsoleLogger()) logging.addHandler(newConsoleLogger())
# Parse arguments # 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) if args["--echo-args"]: stderr.writeLine($args)
@ -269,7 +272,7 @@ Options:
let ctx = initContext(args) let ctx = initContext(args)
## Actual command runners ## Actual command runners
if args["new"]: if args["new"] or args["add"]:
let state = let state =
if args["<state>"]: parseEnum[IssueState]($args["<state>"]) if args["<state>"]: parseEnum[IssueState]($args["<state>"])
else: TodoToday else: TodoToday
@ -302,7 +305,7 @@ Options:
elif args["todo"]: targetState = Todo elif args["todo"]: targetState = Todo
for id in @(args["<id>"]): 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 ctx.triggerPtk:
if targetState == Current: if targetState == Current:
@ -313,6 +316,18 @@ Options:
discard execShellCmd(cmd) discard execShellCmd(cmd)
elif targetState == Done: discard execShellCmd("ptk stop") 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"]: elif args["list"]:
let filter = initFilter() let filter = initFilter()

View File

@ -160,11 +160,13 @@ proc loadIssues*(path: string): seq[Issue] =
if extractFilename(path).match(ISSUE_FILE_PATTERN).isSome(): if extractFilename(path).match(ISSUE_FILE_PATTERN).isSome():
result.add(loadIssue(path)) result.add(loadIssue(path))
proc moveIssue*(tasksDir: string, issue: Issue, newState: IssueState) = proc changeState*(issue: Issue, tasksDir: string, newState: IssueState) =
removeFile(issue.filepath) removeFile(issue.filepath)
if newState == Done: issue.setDateTime("completed", getTime().local) if newState == Done: issue.setDateTime("completed", getTime().local)
tasksDir.store(issue, newState) tasksDir.store(issue, newState)
proc delete*(issue: Issue) = removeFile(issue.filepath)
## Utilities for working with issue collections. ## Utilities for working with issue collections.
proc groupBy*(issues: seq[Issue], propertyKey: string): TableRef[string, seq[Issue]] = proc groupBy*(issues: seq[Issue], propertyKey: string): TableRef[string, seq[Issue]] =
result = newTable[string, seq[Issue]]() result = newTable[string, seq[Issue]]()