#! /usr/bin/env ruby

require 'optparse'
require 'ostruct'
require 'rock/widget_generator'

@usage = "Usage: rock-create-vizkit-widget [options] WIDGET_NAME"
@usage_general = "#{@usage}\nUse option --help for further information."

# Options and their default values
@options = OpenStruct.new
@options.icon_path = ""

opts = OptionParser.new do |opts|
    
    info = <<-EOT
Rock Widget and Designer Plugin Generator

This program generates the essential files needed to implement a vizkit c++ widget. 
EOT
    opts.banner = info + "\n" + @usage
    
    opts.separator ""
    opts.separator "Options:"
    
    # Mandatory argument.
    opts.on("-i", "--icon_path PATH",
            "Path to the icon to be displayed in the Designer's toolbox") do |path|
        @options.icon_path = path
    end
  
end.parse!

# Widget name specified?
if ARGV.length != 1
    puts @usage_general
    exit
end

puts "Enter name of the C++ class being created:"
class_name = $stdin.gets.chomp
raise "Invalid C++ class name: #{class_name}" if class_name =~ /[ \W]/

# Generate widget and designer plugin from arguments and options
Rock::DesignerPluginGenerator.new(ARGV[0],class_name, @options.icon_path, ARGV[1]).generate

puts "Finished. Please update the manifest.xml with package dependencies and other useful information."
