#!/usr/bin/env ruby
# -*- ruby -*-

require 'drb/drb'

require "rabbit/console"

def parse(args=ARGV, logger=nil)
  Rabbit::Console.parse!(args, logger) do |opts, options|
    options.druby_uri = "druby://localhost:10101"
    options.commands = []

    opts.separator ""

    opts.on("--druby-uri=URI",
            _("Specify Rabbit's dRuby URI as [URI]."),
            "(#{options.druby_uri})") do |uri|
      options.druby_uri = uri
    end

    opts.separator(_("Move commands"))

    opts.on("--previous", _("Move to previous")) do
      options.commands << [:move_to_previous_if_can]
    end

    opts.on("--next", _("Move to next")) do
      options.commands << [:move_to_next_if_can]
    end

    opts.on("--previous-slide", _("Move to the previous slide")) do
      options.commands << [:move_to_previous_slide_if_can]
    end

    opts.on("--next-slide", _("Move to the next slide")) do
      options.commands << [:move_to_next_slide_if_can]
    end

    opts.on("--first-slide", _("Move to the first slide")) do
      options.commands << [:move_to_first]
    end

    opts.on("--last-slide", _("Move to the last slide")) do
      options.commands << [:move_to_last]
    end

    opts.on("--jump-to=N", Integer, _("Move to the Nth slide")) do |n|
      options.commands << [:move_to_if_can, n]
    end

    opts.separator(_("Control commands"))

    opts.on("--toggle-fullscreen", _("Toggle fullscreen")) do
      options.commands << [:toggle_fullscreen]
   end

    opts.on("--toggle-index-mode", _("Toggle index mode")) do
      options.commands << [:toggle_index_mode]
   end

    opts.on("--toggle-whiteout", _("Toggle whiteout")) do
      options.commands << [:toggle_whiteout]
   end

    opts.on("--toggle-blackout", _("Toggle blackout")) do
      options.commands << [:toggle_blackout]
   end

    opts.on("--quit", _("Quit")) do
      options.commands << [:quit]
   end
  end
end

def main
  options, logger = parse

  rabbit = DRbObject.new_with_uri(options.druby_uri)
  options.commands.each do |method, *args|
    rabbit.send(method, *args)
  end
end

main
