Add support for binary properties via data URIs.

This commit is contained in:
Jonathan Bernard 2021-06-07 18:34:41 -05:00
parent 98f4dda1ad
commit 9606e71cec
4 changed files with 39 additions and 9 deletions

View File

@ -1,6 +1,6 @@
# Package
version = "4.11.1"
version = "4.12.0"
author = "Jonathan Bernard"
description = "Personal issue tracker."
license = "MIT"
@ -15,10 +15,11 @@ requires @[
"jester 0.5.0",
"uuids 0.1.10",
"https://git.jdb-labs.com/jdb/nim-cli-utils.git >= 0.6.4",
"https://git.jdb-labs.com/jdb/nim-lang-utils.git >= 0.4.0",
"https://git.jdb-labs.com/jdb/nim-time-utils.git >= 0.4.0",
"https://git.jdb-labs.com/jdb/update-nim-package-version"
"https://git.jdb-software.com/jdb/nim-cli-utils.git >= 0.6.4",
"https://git.jdb-software.com/jdb/nim-lang-utils.git >= 0.4.0",
"https://git.jdb-software.com/jdb/nim-time-utils.git >= 0.4.0",
"https://git.jdb-software.com/jdb/nim-data-uri.git >= 1.0.0",
"https://git.jdb-software.com/jdb/update-nim-package-version"
]
task updateVersion, "Update the version of this package.":

View File

@ -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
@ -250,6 +250,8 @@ Usage:
pit reorder <state>
pit delegate <id> <delegated-to>
pit ( delete | rm ) <id>...
pit add-binary-property <id> <propName> <propSource>
pit get-binary-property <id> <propName> <propDest>
Options:
@ -513,6 +515,33 @@ Options:
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()

View File

@ -20,7 +20,7 @@ proc raiseEx(reason: string): void = raise newException(Exception, reason)
template halt(code: HttpCode,
headers: RawHeaders,
content: string): typed =
content: string): void =
## Immediately replies with the specified request. This means any further
## code will not be executed after calling this template in the current
## route.

View File

@ -1 +1 @@
const PIT_VERSION* = "4.11.1"
const PIT_VERSION* = "4.12.0"