#!/usr/bin/ruby

require 'pathname'
include FileTest

DIR  = Pathname.new( __FILE__ ).dirname.dirname.realpath
DICT = DIR + 'doc/aspell.en.pws'

def spellcheck( file )
    puts "Spell checking #{file}"
    system('aspell', '-H', '-p', DICT, '-c', file)
end

ARGC = ARGV.length
if (ARGC == 0) or ((ARGC == 1) and not exists?(ARGV[0]))
    treeish = ARGV[0] || 'master'
    cmd = "git diff --name-only '#{treeish}'"
    files = IO.popen( cmd ).readlines
    for file in files
        next unless file =~ /.*\/.*\.xml$/
        spellcheck file
    end
else
    for file in ARGV
        spellcheck file
    end
end
