bin/tramtracker
#!/usr/bin/env ruby
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'optparse'
require 'tramtracker'
formatter_class = Formatters::PrintFormatter
dotfile = "#{ENV['HOME']}/.tramtracker"
optparse = OptionParser.new do |opts|
opts.banner = "Usage: tramtracker [options] <stop-id>"
opts.on('-p', '--poll', "Poll every 15 seconds") do
formatter_class = Formatters::PollingFormatter
end
opts.on('-v', '--version', 'Display the version of the gem') do
puts "Tramtracker v#{Tramtracker::VERSION}"
exit
end
opts.on('-h', '--help', 'Display this screen') do
puts opts
exit
end
end
optparse.parse!
id = ARGV[0]
id ||= File.read(dotfile).chomp! if File.exists?(dotfile)
unless id
puts optparse
exit 1
end
begin
formatter_class.new(Tramtracker::API.new(id)).report
rescue Interrupt
# Prevent the Exception stack trace from being printed upon ctrl-c
puts # This just puts the next prompt on its own line
end