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
|
# File 'lib/ltsvr/cli.rb', line 15
def self.execute(stdout, arguments=[])
options = {}
options[:keywords] = []
options[:ignore_keywords] = []
options[:filters] = []
opts = OptionParser.new("#{File.basename($0)} [OPTION] [FILE]...")
opts.on("-k LABEL", "--keywords" , "Display keywords (-k host,ua)") {|v| options[:keywords] << v }
opts.on("-i LABEL", "--ignore-keywords", "Ignore keywords (-i time,req)") {|v| options[:ignore_keywords] << v }
opts.on("-f FILTER", "--filter" , "Filtering keywords (-f host=192.168.1.1,ua=Mozilla)") {|v| options[:filters] << v }
opts.on("--web" , "Go to website (http://ltsv.org)") {|v| options[:web] = true }
opts.parse!(arguments)
if options[:web]
Launchy.open('http://ltsv.org')
return
end
obj = Ltsvr.new(options)
if File.pipe?($stdin)
while line = $stdin.gets
result = obj.parse_line(line)
stdout.puts result if result
end
elsif arguments.empty?
stdout.puts opts.help
else
arguments.each do |filename|
io = open(filename)
while line = io.gets
result = obj.parse_line(line)
stdout.puts result if result
end
end
end
end
|