CLI filters added.

remotes/1732436766009665503/tmp_refs/heads/master
Luka Vandervelden 2020-11-23 23:46:59 +01:00
parent 8ab6e5af50
commit 58be7c3d33
1 changed files with 60 additions and 31 deletions

View File

@ -1,34 +1,6 @@
require "tap" require "tap"
require "option_parser" 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 class Storage
def initialize(@root : String = "storage") def initialize(@root : String = "storage")
end end
@ -71,6 +43,49 @@ class Storage
end end
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 storage = Storage.new
enum Tap::Entry::Status enum Tap::Entry::Status
@ -96,9 +111,23 @@ when "add"
storage.store project, environment, revision, STDIN.gets_to_end storage.store project, environment, revision, STDIN.gets_to_end
when "show" when "show"
storage.projects.each do |project| projects = storage.projects.select do |project|
storage.environments(project).each do |environment| show_projects.size == 0 || show_projects.any? &.==(project)
storage.results(project, environment).each do |revision, timestamp, suite| 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 ]" puts "#{project}, #{environment}, #{revision} (#{timestamp}) [ #{suite.size} tests ]"
suite.each do |test| suite.each do |test|
puts " -> #{test.id} #{test.status} #{test.title}" puts " -> #{test.id} #{test.status} #{test.title}"