#!/usr/bin/env ruby
$LOAD_PATH << File.expand_path(File.dirname(__FILE__) + "/../lib")
require 'optparse'
require 'mizuho/generator'

$KCODE = 'UTF-8'
options = {}
parser = OptionParser.new do |opts|
	opts.banner = "Usage: mizuho [options] INPUT"
	opts.separator ""
	
	opts.separator "Options:"
	opts.on("-t", "--template FILE", String, "Specify a template file to use.") do |value|
		options[:template] = value
	end
	opts.on("-m", "--multi-page", "Generate one file per chapter.") do |value|
		options[:multi_page] = value
	end
	opts.on("--icons-dir DIR", "Specify the directory in which icons\n" <<
		"#{' ' * 37}should be searched. Defaults to\n" <<
		"#{' ' * 37}'images/icons'.") do |value|
		options[:icons_dir] = value
	end
end
begin
	parser.parse!
rescue OptionParser::ParseError => e
	puts e
	puts
	puts "Please see '--help' for valid options."
	exit 1
end

begin
	Mizuho::Generator.new(ARGV[0], nil, options[:template],
		options[:multi_page], options[:icons_dir]).start
rescue Mizuho::GenerationError
	STDERR.puts "*** ERROR"
	exit 2
end
