CLI filters added.

This commit is contained in:
Luka Vandervelden 2020-11-23 23:46:59 +01:00
parent 8ab6e5af50
commit 58be7c3d33

View File

@ -1,34 +1,6 @@
require "tap"
require "option_parser"
args = Array(String).new
OptionParser.parse! do |parser|
parser.banner = "usage: tap-aggregator <command> [options]"
parser.on("-h", "--help", "Show this help") do
puts parser
exit 0
end
parser.invalid_option do |flag|
STDERR.puts "ERROR: #{flag} is not a valid option."
STDERR.puts parser
exit 1
end
parser.unknown_args do |x|
args = x
if args.size < 1
puts parser
exit 1
end
end
end
command = args[0]
class Storage
def initialize(@root : String = "storage")
end
@ -71,6 +43,49 @@ class Storage
end
end
args = Array(String).new
show_projects = [] of String
show_environments = [] of String
show_revisions = [] of String
OptionParser.parse! do |parser|
parser.banner = "usage: tap-aggregator <command> [options]"
parser.on("-h", "--help", "Show this help") do
puts parser
exit 0
end
parser.on("-p id", "--project id", "Filter results that do not match this project.") do |id|
show_projects << id
end
parser.on("-e id", "--environment id", "Filter results that do not match this environment.") do |id|
show_environments << id
end
parser.on("-r id", "--revision id", "Filter results that do not match this revision id.") do |id|
show_revisions << id
end
parser.invalid_option do |flag|
STDERR.puts "ERROR: #{flag} is not a valid option."
STDERR.puts parser
exit 1
end
parser.unknown_args do |x|
args = x
if args.size < 1
puts parser
exit 1
end
end
end
command = args[0]
storage = Storage.new
enum Tap::Entry::Status
@ -96,9 +111,23 @@ when "add"
storage.store project, environment, revision, STDIN.gets_to_end
when "show"
storage.projects.each do |project|
storage.environments(project).each do |environment|
storage.results(project, environment).each do |revision, timestamp, suite|
projects = storage.projects.select do |project|
show_projects.size == 0 || show_projects.any? &.==(project)
end
projects.each do |project|
environments = storage.environments(project).select do |environment|
show_environments.size == 0 || show_environments.any? &.==(environment)
end
environments.each do |environment|
# FIXME: This currently parses everything, including entries
# that are not going to be displayed.
results = storage.results(project, environment).select do |revision, timestamp, suite|
show_revisions.size == 0 || show_revisions.any? &.==(revision)
end
results.each do |revision, timestamp, suite|
puts "#{project}, #{environment}, #{revision} (#{timestamp}) [ #{suite.size} tests ]"
suite.each do |test|
puts " -> #{test.id} #{test.status} #{test.title}"