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
|
# File 'lib/vantage/cli.rb', line 11
def run!
ARGV.options do |o|
list = false
urls = []
point = Vantage::Config.point_list.sample
o.set_summary_indent(" ")
o.banner = "Usage: vantage [OPTIONS]"
o.banner += "\nExample: vantage -u http://google.com,http://yahoo.com"
o.on('-l', '--list-points', 'List allowed vantage points') { list = true }
o.on('-u', '--urls URLS', Array, 'List of urls to check') { |list| urls = list }
o.on('-p', '--point POINT', String, 'Vantage point to check from. If not set, will use a random point') { |p| point = p }
o.parse!
if list
puts Vantage::Config.point_list.join("\n")
else
abort("Error: --urls is required\n\n#{o}") if urls.empty?
abort("Error: specified point does not exist\n\n#{o}") unless Vantage::Config.point_list.include?(point)
checks = urls.map { |u| { "url" => u } }
json = Vantage::Client.new.check("checks" => checks, "point" => point)
results = OkJson.decode(json)
results.each { |r| emit(r) }
end
end
end
|