#!/usr/bin/env ruby
require 'org-ruby'
require 'optparse'

options = {}
options_parser = OptionParser.new do |opts|
  options[:help] = false
  options[:format] = :html
  
  opts.banner = "Usage: org-ruby <file> [options]"

  opts.on("-h", "--help", "Show this message") do |v|
    options[:help] = true
  end

  opts.on("-d", "--debug", "Run with $DEBUG true") do |v|
    options[:debug] = true
  end

  opts.on("-t", "--translate FORMAT", [:html, :textile],
          "Translate the ORG file to the specified format.") do |v|
    options[:format] = v
  end

  opts.on("-v", "--version", "Print version") do |v|
    options[:version] = true
  end
end

begin
  options_parser.parse!

  if options[:version]
    puts OrgRuby::VERSION
    exit
  end

  if (ARGV.length == 0) then
    puts options_parser
  else
    data = IO.read(ARGV[0])
    p = Orgmode::Parser.new(data)
    $DEBUG = true if options[:debug]
    puts p.to_html if options[:format] == :html
    puts p.to_textile if options[:format] == :textile
  end
rescue OptionParser::ParseError
  puts options_parser
end


