Move filter logic earlier in CLI processing, support state filtering.
This commit is contained in:
97
src/pit.nim
97
src/pit.nim
@@ -31,6 +31,7 @@ proc parseExclPropertiesOption(propsOpt: string): TableRef[string, seq[string]]
|
||||
if result.hasKey(pair[0]): result[pair[0]].add(val)
|
||||
else: result[pair[0]] = @[val]
|
||||
|
||||
|
||||
proc reorder(ctx: CliContext, state: IssueState) =
|
||||
|
||||
# load the issues to make sure the order file contains all issues in the state.
|
||||
@@ -87,6 +88,10 @@ when isMainModule:
|
||||
var tagsOption = none(seq[string])
|
||||
var exclTagsOption = none(seq[string])
|
||||
|
||||
let filter = initFilter()
|
||||
var filterOption = none(IssueFilter)
|
||||
|
||||
|
||||
if args["--properties"] or args["--context"]:
|
||||
|
||||
var props =
|
||||
@@ -116,6 +121,54 @@ when isMainModule:
|
||||
if args["--excl-tags"]: exclTagsOption =
|
||||
some(($args["--excl-tags"]).split(",").mapIt(it.strip))
|
||||
|
||||
# Initialize filter with properties (if given)
|
||||
if propertiesOption.isSome:
|
||||
filter.properties = propertiesOption.get
|
||||
filterOption = some(filter)
|
||||
|
||||
# Add property exclusions (if given)
|
||||
if exclPropsOption.isSome:
|
||||
filter.exclProperties = exclPropsOption.get
|
||||
filterOption = some(filter)
|
||||
|
||||
# If they supplied text matches, add that to the filter.
|
||||
if args["--match"]:
|
||||
filter.summaryMatch = some(re("(?i)" & $args["--match"]))
|
||||
filterOption = some(filter)
|
||||
|
||||
if args["--match-all"]:
|
||||
filter.fullMatch = some(re("(?i)" & $args["--match-all"]))
|
||||
filterOption = some(filter)
|
||||
|
||||
# If no "context" property is given, use the default (if we have one)
|
||||
if ctx.defaultContext.isSome and not filter.properties.hasKey("context"):
|
||||
stderr.writeLine("Limiting to default context: " & ctx.defaultContext.get)
|
||||
filter.properties["context"] = ctx.defaultContext.get
|
||||
filterOption = some(filter)
|
||||
|
||||
if tagsOption.isSome:
|
||||
filter.hasTags = tagsOption.get
|
||||
filterOption = some(filter)
|
||||
|
||||
if exclTagsOption.isSome:
|
||||
filter.exclTags = exclTagsOption.get
|
||||
filterOption = some(filter)
|
||||
|
||||
if args["--today"]:
|
||||
filter.inclStates.add(@[Current, TodoToday, Pending])
|
||||
filterOption = some(filter)
|
||||
|
||||
if args["--future"]:
|
||||
filter.inclStates.add(@[Pending, Todo])
|
||||
filterOption = some(filter)
|
||||
|
||||
# Finally, if the "context" is "all", don't filter on context
|
||||
if filter.properties.hasKey("context") and
|
||||
filter.properties["context"] == "all":
|
||||
|
||||
filter.properties.del("context")
|
||||
filter.exclProperties.del("context")
|
||||
|
||||
## Actual command runners
|
||||
if args["new"] or args["add"]:
|
||||
let state =
|
||||
@@ -224,7 +277,6 @@ when isMainModule:
|
||||
updatedIssues.add(nextIssue)
|
||||
stdout.writeLine formatIssue(nextIssue)
|
||||
|
||||
|
||||
issue.changeState(ctx.cfg.tasksDir, targetState)
|
||||
updatedIssues.add(issue)
|
||||
|
||||
@@ -276,49 +328,6 @@ when isMainModule:
|
||||
|
||||
elif args["list"]:
|
||||
|
||||
let filter = initFilter()
|
||||
var filterOption = none(IssueFilter)
|
||||
|
||||
# Initialize filter with properties (if given)
|
||||
if propertiesOption.isSome:
|
||||
filter.properties = propertiesOption.get
|
||||
filterOption = some(filter)
|
||||
|
||||
# Add property exclusions (if given)
|
||||
if exclPropsOption.isSome:
|
||||
filter.exclProperties = exclPropsOption.get
|
||||
filterOption = some(filter)
|
||||
|
||||
# If they supplied text matches, add that to the filter.
|
||||
if args["--match"]:
|
||||
filter.summaryMatch = some(re("(?i)" & $args["--match"]))
|
||||
filterOption = some(filter)
|
||||
|
||||
if args["--match-all"]:
|
||||
filter.fullMatch = some(re("(?i)" & $args["--match-all"]))
|
||||
filterOption = some(filter)
|
||||
|
||||
# If no "context" property is given, use the default (if we have one)
|
||||
if ctx.defaultContext.isSome and not filter.properties.hasKey("context"):
|
||||
stderr.writeLine("Limiting to default context: " & ctx.defaultContext.get)
|
||||
filter.properties["context"] = ctx.defaultContext.get
|
||||
filterOption = some(filter)
|
||||
|
||||
if tagsOption.isSome:
|
||||
filter.hasTags = tagsOption.get
|
||||
filterOption = some(filter)
|
||||
|
||||
if exclTagsOption.isSome:
|
||||
filter.exclTags = exclTagsOption.get
|
||||
filterOption = some(filter)
|
||||
|
||||
# Finally, if the "context" is "all", don't filter on context
|
||||
if filter.properties.hasKey("context") and
|
||||
filter.properties["context"] == "all":
|
||||
|
||||
filter.properties.del("context")
|
||||
filter.exclProperties.del("context")
|
||||
|
||||
var listContexts = false
|
||||
var listTags = false
|
||||
var statesOption = none(seq[IssueState])
|
||||
|
||||
Reference in New Issue
Block a user