Add show-dupes command, fix BareExcept warnings.

This commit is contained in:
Jonathan Bernard 2023-05-19 09:24:53 -05:00
parent 6665f09b7b
commit 661d5959c6
4 changed files with 29 additions and 9 deletions

View File

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

View File

@ -226,7 +226,7 @@ proc edit(issue: Issue) =
# Try to parse the newly-edited issue to make sure it was successful.
let editedIssue = loadIssue(issue.filepath)
editedIssue.store()
except:
except CatchableError:
fatal "updated issue is invalid (ignoring edits): \n\t" &
getCurrentExceptionMsg()
issue.store()
@ -392,7 +392,7 @@ when isMainModule:
var stateOption = none(IssueState)
try: stateOption = some(parseEnum[IssueState](editRef))
except: discard
except CatchableError: discard
if stateOption.isSome:
let state = stateOption.get
@ -545,8 +545,12 @@ when isMainModule:
if args["contexts"]: listContexts = true
elif args["<stateOrId>"]:
try: statesOption = some(args["<stateOrId>"].mapIt(parseEnum[IssueState]($it)))
except: issueIdsOption = some(args["<stateOrId>"].mapIt($it))
try:
statesOption =
some(args["<stateOrId>"].
mapIt(parseEnum[IssueState]($it)))
except CatchableError:
issueIdsOption = some(args["<stateOrId>"].mapIt($it))
# List the known contexts
if listContexts:
@ -610,7 +614,22 @@ when isMainModule:
try: write(propOut, decodeDataUri(issue[$(args["<propName>"])]))
finally: close(propOut)
except:
elif args["show-dupes"]:
ctx.loadAllIssues()
var idsToPaths = newTable[string, var seq[string]]()
for (state, issues) in pairs(ctx.issues):
for issue in issues:
let issueId = $issue.id
if idsToPaths.hasKey(issueId): idsToPaths[issueId].add(issue.filepath)
else: idsToPaths[issueId] = @[issue.filepath]
for (issueId, issuePaths) in pairs(idsToPaths):
if issuePaths.len < 2: continue
stdout.writeLine(issueId & ":\p " & issuePaths.join("\p ") & "\p\p")
except CatchableError:
fatal getCurrentExceptionMsg()
debug getCurrentException().getStackTrace()
#raise getCurrentException()

View File

@ -1,4 +1,4 @@
const PIT_VERSION* = "4.23.3"
const PIT_VERSION* = "4.23.4"
const USAGE* = """Usage:
pit ( new | add) <summary> [<state>] [options]
@ -14,6 +14,7 @@ const USAGE* = """Usage:
pit ( delete | rm ) <id>... [options]
pit add-binary-property <id> <propName> <propSource> [options]
pit get-binary-property <id> <propName> <propDest> [options]
pit show-dupes
pit help [options]
Options:

View File

@ -168,7 +168,7 @@ proc parseDate*(d: string): DateTime =
var errMsg = ""
for df in DATE_FORMATS:
try: return d.parse(df)
except:
except CatchableError:
errMsg &= "\n\tTried " & df & " with " & d
continue
raise newException(ValueError, "Unable to parse input as a date: " & d & errMsg)
@ -426,7 +426,7 @@ proc loadConfig*(args: Table[string, Value] = initTable[string, Value]()): PitCo
try:
cfgFile = open(pitrcFilename, fmWrite)
cfgFile.write("{\"tasksDir\": \"/path/to/tasks\"}")
except: warn "could not write default .pitrc to " & pitrcFilename
except CatchableError: warn "could not write default .pitrc to " & pitrcFilename
finally: close(cfgFile)
debug "loading config from '$#'" % [pitrcFilename]