Allow including or excluding properties by name only.
This commit is contained in:
11
src/pit.nim
11
src/pit.nim
@@ -19,18 +19,16 @@ proc parsePropertiesOption(propsOpt: string): TableRef[string, string] =
|
|||||||
result = newTable[string, string]()
|
result = newTable[string, string]()
|
||||||
for propText in propsOpt.split(";"):
|
for propText in propsOpt.split(";"):
|
||||||
let pair = propText.split(":", 1)
|
let pair = propText.split(":", 1)
|
||||||
if pair.len == 1: result[pair[0]] = "true"
|
if pair.len == 1: result[pair[0]] = MATCH_ANY
|
||||||
else: result[pair[0]] = pair[1]
|
else: result[pair[0]] = pair[1]
|
||||||
|
|
||||||
|
|
||||||
proc parseExclPropertiesOption(propsOpt: string): TableRef[string, seq[string]] =
|
proc parseExclPropertiesOption(propsOpt: string): TableRef[string, seq[string]] =
|
||||||
result = newTable[string, seq[string]]()
|
result = newTable[string, seq[string]]()
|
||||||
for propText in propsOpt.split(";"):
|
for propText in propsOpt.split(";"):
|
||||||
let pair = propText.split(":", 1)
|
let pair = propText.split(":", 1)
|
||||||
let val =
|
if not result.hasKey(pair[0]): result[pair[0]] = @[]
|
||||||
if pair.len == 1: "true"
|
if pair.len == 2: result[pair[0]].add(pair[1])
|
||||||
else: pair[1]
|
|
||||||
if result.hasKey(pair[0]): result[pair[0]].add(val)
|
|
||||||
else: result[pair[0]] = @[val]
|
|
||||||
|
|
||||||
|
|
||||||
proc reorder(ctx: CliContext, state: IssueState) =
|
proc reorder(ctx: CliContext, state: IssueState) =
|
||||||
@@ -39,6 +37,7 @@ proc reorder(ctx: CliContext, state: IssueState) =
|
|||||||
ctx.loadIssues(state)
|
ctx.loadIssues(state)
|
||||||
discard os.execShellCmd(EDITOR & " '" & (ctx.cfg.tasksDir / $state / "order.txt") & "' </dev/tty >/dev/tty")
|
discard os.execShellCmd(EDITOR & " '" & (ctx.cfg.tasksDir / $state / "order.txt") & "' </dev/tty >/dev/tty")
|
||||||
|
|
||||||
|
|
||||||
proc addIssue(
|
proc addIssue(
|
||||||
ctx: CliContext,
|
ctx: CliContext,
|
||||||
args: Table[string, Value],
|
args: Table[string, Value],
|
||||||
|
|||||||
@@ -33,12 +33,20 @@ Options:
|
|||||||
a filter to the issues listed, only allowing those
|
a filter to the issues listed, only allowing those
|
||||||
which have all of the given properties.
|
which have all of the given properties.
|
||||||
|
|
||||||
|
If a propert name is provided without a value, this
|
||||||
|
will allow all issues which have any value defined
|
||||||
|
for the named property.
|
||||||
|
|
||||||
-P, --excl-properties <props>
|
-P, --excl-properties <props>
|
||||||
When used with the list command, exclude issues
|
When used with the list command, exclude issues
|
||||||
that contain properties with the given value. This
|
that contain properties with the given value. This
|
||||||
parameter is formatted the same as the --properties
|
parameter is formatted the same as the --properties
|
||||||
parameter: "key:val;key:val"
|
parameter: "key:val;key:val"
|
||||||
|
|
||||||
|
If no value is provided for a property, this will
|
||||||
|
filter out all issues with *any* value for that
|
||||||
|
property.
|
||||||
|
|
||||||
-c, --context <ctx> Shorthand for '-p context:<ctx>'
|
-c, --context <ctx> Shorthand for '-p context:<ctx>'
|
||||||
|
|
||||||
-C, --excl-context <ctx> Don't show issues from the given context(s).
|
-C, --excl-context <ctx> Don't show issues from the given context(s).
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ type
|
|||||||
isFromCompletion*: bool
|
isFromCompletion*: bool
|
||||||
|
|
||||||
|
|
||||||
|
const MATCH_ANY* = "<match-any>"
|
||||||
const DONE_FOLDER_FORMAT* = "yyyy-MM"
|
const DONE_FOLDER_FORMAT* = "yyyy-MM"
|
||||||
const ISO8601_MS = "yyyy-MM-dd'T'HH:mm:ss'.'fffzzz"
|
const ISO8601_MS = "yyyy-MM-dd'T'HH:mm:ss'.'fffzzz"
|
||||||
|
|
||||||
@@ -429,10 +430,16 @@ proc filter*(issues: seq[Issue], filter: IssueFilter): seq[Issue] =
|
|||||||
it.getDateTime("hide-until") <= now)
|
it.getDateTime("hide-until") <= now)
|
||||||
|
|
||||||
for k,v in filter.properties:
|
for k,v in filter.properties:
|
||||||
f = f --> filter(it.hasProp(k) and it[k] == v)
|
if v == MATCH_ANY:
|
||||||
|
f = f --> filter(it.hasProp(k))
|
||||||
|
else:
|
||||||
|
f = f --> filter(it.hasProp(k) and it[k] == v)
|
||||||
|
|
||||||
for k,v in filter.exclProperties:
|
for k,v in filter.exclProperties:
|
||||||
f = f --> filter(not (it.hasProp(k) and v.contains(it[k])))
|
if v.len == 0:
|
||||||
|
f = f --> filter(not (it.hasProp(k)))
|
||||||
|
else:
|
||||||
|
f = f --> filter(not (it.hasProp(k) and v.contains(it[k])))
|
||||||
|
|
||||||
if filter.completedRange.isSome:
|
if filter.completedRange.isSome:
|
||||||
let range = filter.completedRange.get
|
let range = filter.completedRange.get
|
||||||
|
|||||||
Reference in New Issue
Block a user