simongregory/auntie

View on GitHub
bin/weather

Summary

Maintainability
Test Coverage
#!/usr/bin/env ruby
require 'auntie'

if ARGV[0] == 'help' && ARGV[1] == '-c'
  # loc-search doesn't seem to be compatible with zsh completion?
  puts "--location-search\n--hourly\n--daily"
  exit
end

if %w(help -h --help).include? ARGV[0]
  puts 'Useage: weather <Postcode or BBC location id>'
  puts '                --location-search <place name>'
  puts '                --hourly <Postcode or BBC location id>'
  puts '                --daily <Postcode or BBC location id>'
  exit
end

if ARGV[0] == '--location-search'
  place = ARGV[1..-1].join(' ')

  abort 'Please specify a location to search for.' if place.empty?
  place = 'Hadfield' if place.downcase == 'royston vasey'

  Location.new.find(place)
  exit
end

def location
  ARGV[0] ||= '2643743' # Default to London.
end

action = ARGV[0]

if action == '--daily'
  ARGV.shift
  Weather.new(location).daily
elsif action == '--hourly'
  ARGV.shift
  Weather.new(location).hourly
else
  Weather.new(location).hourly
end