mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Support tag filtering with value
This commit is contained in:
parent
b79dd4361e
commit
a9a46c76ad
2 changed files with 9 additions and 4 deletions
|
@ -139,11 +139,16 @@ module Spectator
|
||||||
|
|
||||||
# Adds the tag filter option to the parser.
|
# Adds the tag filter option to the parser.
|
||||||
private def tag_option(parser, builder)
|
private def tag_option(parser, builder)
|
||||||
parser.on("--tag TAG", "run examples with the specified TAG, or exclude examples by adding ~ before the TAG.") do |tag|
|
parser.on("--tag TAG[:VALUE]", "Run examples with the specified TAG, or exclude examples by adding ~ before the TAG.") do |tag|
|
||||||
negated = tag.starts_with?('~')
|
negated = tag.starts_with?('~')
|
||||||
tag = tag.lchop('~')
|
tag = tag.lchop('~')
|
||||||
Log.debug { "Filtering for example with tag #{tag}" }
|
Log.debug { "Filtering for example with tag #{tag}" }
|
||||||
filter = TagNodeFilter.new(tag)
|
parts = tag.split(':', 2, remove_empty: true)
|
||||||
|
if parts.size > 1
|
||||||
|
tag = parts.first
|
||||||
|
value = parts.last
|
||||||
|
end
|
||||||
|
filter = TagNodeFilter.new(tag, value)
|
||||||
builder.add_node_filter(filter)
|
builder.add_node_filter(filter)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,12 +5,12 @@ module Spectator
|
||||||
class TagNodeFilter < NodeFilter
|
class TagNodeFilter < NodeFilter
|
||||||
# Creates the filter.
|
# Creates the filter.
|
||||||
# The *tag* indicates which tag the node must have in its metadata.
|
# The *tag* indicates which tag the node must have in its metadata.
|
||||||
def initialize(@tag : String)
|
def initialize(@tag : String, @value : String? = nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Checks whether the node satisfies the filter.
|
# Checks whether the node satisfies the filter.
|
||||||
def includes?(node) : Bool
|
def includes?(node) : Bool
|
||||||
node.metadata.each_key.any? { |key| key.to_s == @tag }
|
node.metadata.any? { |key, value| key.to_s == @tag && (!@value || value == @value) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue