/
cli.rb
106 lines (84 loc) · 2.35 KB
/
cli.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
module Tapout
require 'optparse'
# Command line interface.
#
def self.cli(*argv)
options = {}
type = :modern
parser = OptionParser.new do |opt|
opt.banner = "tapout [options] [reporter]"
opt.separator("\nOPTIONS:")
#opt.on('-t', '--tap', 'Consume legacy TAP input') do |fmt|
# type = :legacy
#end
opt.on('--trace', '-t DEPTH', 'set backtrace depth') do |depth|
self.config.trace = depth
end
opt.on('--lines', '-l LINES', 'number of surrounding source code lines') do |lines|
self.config.lines = lines.to_i
end
opt.on('--minimal', '-m', 'show only errors, failures and pending tests') do |val|
self.config.minimal = val
end
opt.on('--no-color', 'suppress ANSI color codes') do
$ansi = false
end
opt.on('--require', '-r FEATURE', 'require feature') do |feature|
require feature
end
#opt.on('--plugin', '-p NAME', 'Require plugin feature (tapout-<name>)') do |name|
# require "tapout-#{name}"
#end
opt.on('--debug', 'run with $DEBUG flag on') do |fmt|
$DEBUG = true
end
opt.separator("\nREPORTERS:\n " + Reporters.index.keys.join("\n "))
end
parser.parse!(argv)
options[:format] = argv.first
# TODO: would be nice if it could automatically determine which
#c = $stdin.getc
# $stdin.pos = 0
#type = :legacy if c =~ /\d/
#type = :modern if c == '-'
stdin = Curmudgeon.new($stdin)
case stdin.line1
when /^\d/
type = :perl
when /^\-/
type = :yaml
when /^\{/
type = :json
else
raise "Not a recognized TAP stream!"
end
case type
when :perl
stream_parser = PerlParser.new(options)
exit_code = stream_parser.consume(stdin)
when :yaml
stream_parser = YamlParser.new(options)
exit_code = stream_parser.consume(stdin)
when :json
stream_parser = JsonParser.new(options)
exit_code = stream_parser.consume(stdin)
end
exit(exit_code || 0)
end
#
class Curmudgeon #< IO
def initialize(input)
@input = input
@line1 = input.gets
end
def line1
@line1
end
def gets
(class << self; self; end).class_eval %{
def gets; @input.gets; end
}
return @line1
end
end
end