|
|
|
@ -1,8 +1,8 @@
|
|
|
|
|
## Personal Issue Tracker CLI interface
|
|
|
|
|
## ====================================
|
|
|
|
|
|
|
|
|
|
import algorithm, cliutils, docopt, json, logging, options, os, sequtils,
|
|
|
|
|
std/wordwrap, tables, terminal, times, timeutils, unicode, uuids
|
|
|
|
|
import algorithm, cliutils, data_uri, docopt, json, logging, options, os,
|
|
|
|
|
sequtils, std/wordwrap, tables, terminal, times, timeutils, unicode, uuids
|
|
|
|
|
|
|
|
|
|
from nre import re
|
|
|
|
|
import strutils except alignLeft, capitalize, strip, toUpper, toLower
|
|
|
|
@ -70,6 +70,8 @@ proc formatIssue(ctx: CliContext, issue: Issue): string =
|
|
|
|
|
if not issue.details.isEmptyOrWhitespace:
|
|
|
|
|
result &= issue.details.strip.withColor(fgCyan) & "\n"
|
|
|
|
|
|
|
|
|
|
result &= termReset
|
|
|
|
|
|
|
|
|
|
proc formatSectionIssue(ctx: CliContext, issue: Issue, width: int, indent = "",
|
|
|
|
|
verbose = false): string =
|
|
|
|
|
|
|
|
|
@ -194,22 +196,23 @@ proc edit(issue: Issue) =
|
|
|
|
|
getCurrentExceptionMsg()
|
|
|
|
|
issue.store()
|
|
|
|
|
|
|
|
|
|
proc list(ctx: CliContext, filter: Option[IssueFilter], state: Option[IssueState], showToday, showFuture, verbose: bool) =
|
|
|
|
|
proc list(ctx: CliContext, filter: Option[IssueFilter], states: Option[seq[IssueState]], showToday, showFuture, verbose: bool) =
|
|
|
|
|
|
|
|
|
|
if state.isSome:
|
|
|
|
|
ctx.loadIssues(state.get)
|
|
|
|
|
if filter.isSome: ctx.filterIssues(filter.get)
|
|
|
|
|
if state.get == Done and showToday:
|
|
|
|
|
ctx.issues[Done] = ctx.issues[Done].filterIt(
|
|
|
|
|
it.hasProp("completed") and
|
|
|
|
|
sameDay(getTime().local, it.getDateTime("completed")))
|
|
|
|
|
stdout.write ctx.formatSection(ctx.issues[state.get], state.get, "", verbose)
|
|
|
|
|
if states.isSome:
|
|
|
|
|
for state in states.get:
|
|
|
|
|
ctx.loadIssues(state)
|
|
|
|
|
if filter.isSome: ctx.filterIssues(filter.get)
|
|
|
|
|
if state == Done and showToday:
|
|
|
|
|
ctx.issues[Done] = ctx.issues[Done].filterIt(
|
|
|
|
|
it.hasProp("completed") and
|
|
|
|
|
sameDay(getTime().local, it.getDateTime("completed")))
|
|
|
|
|
stdout.write ctx.formatSection(ctx.issues[state], state, "", verbose)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
ctx.loadAllIssues()
|
|
|
|
|
if filter.isSome: ctx.filterIssues(filter.get)
|
|
|
|
|
|
|
|
|
|
let today = showToday and [Current, TodoToday].anyIt(
|
|
|
|
|
let today = showToday and [Current, TodoToday, Pending].anyIt(
|
|
|
|
|
ctx.issues.hasKey(it) and ctx.issues[it].len > 0)
|
|
|
|
|
|
|
|
|
|
let future = showFuture and [Pending, Todo].anyIt(
|
|
|
|
@ -221,7 +224,7 @@ proc list(ctx: CliContext, filter: Option[IssueFilter], state: Option[IssueState
|
|
|
|
|
if today:
|
|
|
|
|
if future: ctx.writeHeader("Today")
|
|
|
|
|
|
|
|
|
|
for s in [Current, TodoToday]:
|
|
|
|
|
for s in [Current, TodoToday, Pending]:
|
|
|
|
|
if ctx.issues.hasKey(s) and ctx.issues[s].len > 0:
|
|
|
|
|
stdout.write ctx.formatSection(ctx.issues[s], s, indent, verbose)
|
|
|
|
|
|
|
|
|
@ -231,7 +234,11 @@ proc list(ctx: CliContext, filter: Option[IssueFilter], state: Option[IssueState
|
|
|
|
|
|
|
|
|
|
for s in [Pending, Todo]:
|
|
|
|
|
if ctx.issues.hasKey(s) and ctx.issues[s].len > 0:
|
|
|
|
|
stdout.write ctx.formatSection(ctx.issues[s], s, indent, verbose)
|
|
|
|
|
let visibleIssues = ctx.issues[s].filterIt(
|
|
|
|
|
not (it.hasProp("hide-until") and
|
|
|
|
|
it.getDateTime("hide-until") > getTime().local))
|
|
|
|
|
|
|
|
|
|
stdout.write ctx.formatSection(visibleIssues, s, indent, verbose)
|
|
|
|
|
|
|
|
|
|
when isMainModule:
|
|
|
|
|
|
|
|
|
@ -239,15 +246,18 @@ when isMainModule:
|
|
|
|
|
let doc = """
|
|
|
|
|
Usage:
|
|
|
|
|
pit ( new | add) <summary> [<state>] [options]
|
|
|
|
|
pit list contexts
|
|
|
|
|
pit list [<stateOrId>] [options]
|
|
|
|
|
pit list contexts [options]
|
|
|
|
|
pit list [<stateOrId>...] [options]
|
|
|
|
|
pit ( start | done | pending | todo-today | todo | suspend ) <id>... [options]
|
|
|
|
|
pit edit <ref>...
|
|
|
|
|
pit edit <ref>... [options]
|
|
|
|
|
pit tag <id>... [options]
|
|
|
|
|
pit untag <id>... [options]
|
|
|
|
|
pit reorder <state>
|
|
|
|
|
pit reorder <state> [options]
|
|
|
|
|
pit delegate <id> <delegated-to>
|
|
|
|
|
pit ( delete | rm ) <id>...
|
|
|
|
|
pit hide-until <id> <date> [options]
|
|
|
|
|
pit ( delete | rm ) <id>... [options]
|
|
|
|
|
pit add-binary-property <id> <propName> <propSource> [options]
|
|
|
|
|
pit get-binary-property <id> <propName> <propDest> [options]
|
|
|
|
|
|
|
|
|
|
Options:
|
|
|
|
|
|
|
|
|
@ -419,6 +429,13 @@ Options:
|
|
|
|
|
elif targetState == Done or targetState == Pending:
|
|
|
|
|
discard execShellCmd("ptk stop")
|
|
|
|
|
|
|
|
|
|
elif args["hide-until"]:
|
|
|
|
|
|
|
|
|
|
let issue = ctx.tasksDir.loadIssueById($(args["<id>"]))
|
|
|
|
|
issue.setDateTime("hide-until", parseDate($args["<date>"]))
|
|
|
|
|
|
|
|
|
|
issue.store()
|
|
|
|
|
|
|
|
|
|
elif args["delegate"]:
|
|
|
|
|
|
|
|
|
|
let issue = ctx.tasksDir.loadIssueById($(args["<id>"]))
|
|
|
|
@ -474,13 +491,13 @@ Options:
|
|
|
|
|
filter.properties.del("context")
|
|
|
|
|
|
|
|
|
|
var listContexts = false
|
|
|
|
|
var stateOption = none(IssueState)
|
|
|
|
|
var issueIdOption = none(string)
|
|
|
|
|
var statesOption = none(seq[IssueState])
|
|
|
|
|
var issueIdsOption = none(seq[string])
|
|
|
|
|
|
|
|
|
|
if args["contexts"]: listContexts = true
|
|
|
|
|
elif args["<stateOrId>"]:
|
|
|
|
|
try: stateOption = some(parseEnum[IssueState]($args["<stateOrId>"]))
|
|
|
|
|
except: issueIdOption = some($args["<stateOrId>"])
|
|
|
|
|
try: statesOption = some(args["<stateOrId>"].mapIt(parseEnum[IssueState]($it)))
|
|
|
|
|
except: issueIdsOption = some(args["<stateOrId>"].mapIt($it))
|
|
|
|
|
|
|
|
|
|
# List the known contexts
|
|
|
|
|
if listContexts:
|
|
|
|
@ -500,17 +517,45 @@ Options:
|
|
|
|
|
stdout.writeLine(c.alignLeft(maxLen+2) & ctx.getIssueContextDisplayName(c))
|
|
|
|
|
|
|
|
|
|
# List a specific issue
|
|
|
|
|
elif issueIdOption.isSome:
|
|
|
|
|
let issue = ctx.tasksDir.loadIssueById(issueIdOption.get)
|
|
|
|
|
stdout.writeLine ctx.formatIssue(issue)
|
|
|
|
|
elif issueIdsOption.isSome:
|
|
|
|
|
for issueId in issueIdsOption.get:
|
|
|
|
|
let issue = ctx.tasksDir.loadIssueById(issueId)
|
|
|
|
|
stdout.writeLine ctx.formatIssue(issue)
|
|
|
|
|
|
|
|
|
|
# List all issues
|
|
|
|
|
else:
|
|
|
|
|
let showBoth = args["--today"] == args["--future"]
|
|
|
|
|
ctx.list(filterOption, stateOption, showBoth or args["--today"],
|
|
|
|
|
ctx.list(filterOption, statesOption, showBoth or args["--today"],
|
|
|
|
|
showBoth or args["--future"],
|
|
|
|
|
ctx.verbose)
|
|
|
|
|
|
|
|
|
|
elif args["add-binary-property"]:
|
|
|
|
|
let issue = ctx.tasksDir.loadIssueById($(args["<id>"]))
|
|
|
|
|
|
|
|
|
|
let propIn =
|
|
|
|
|
if $(args["<propSource>"]) == "-": stdin
|
|
|
|
|
else: open($(args["<propSource>"]))
|
|
|
|
|
|
|
|
|
|
try: issue[$(args["<propName>"])] = encodeAsDataUri(readAll(propIn))
|
|
|
|
|
finally: close(propIn)
|
|
|
|
|
|
|
|
|
|
issue.store()
|
|
|
|
|
|
|
|
|
|
elif args["get-binary-property"]:
|
|
|
|
|
let issue = ctx.tasksDir.loadIssueById($(args["<id>"]))
|
|
|
|
|
|
|
|
|
|
if not issue.hasProp($(args["<propName>"])):
|
|
|
|
|
raise newException(Exception,
|
|
|
|
|
"issue " & ($issue.id)[0..<6] & " has no property name '" &
|
|
|
|
|
$(args["<propName>"]) & "'")
|
|
|
|
|
|
|
|
|
|
let propOut =
|
|
|
|
|
if $(args["<propDest>"]) == "-": stdout
|
|
|
|
|
else: open($(args["<propDest>"]), fmWrite)
|
|
|
|
|
|
|
|
|
|
try: write(propOut, decodeDataUri(issue[$(args["<propName>"])]))
|
|
|
|
|
finally: close(propOut)
|
|
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
fatal "pit: " & getCurrentExceptionMsg()
|
|
|
|
|
#raise getCurrentException()
|
|
|
|
|