#!/usr/bin/env ruby
require_relative 'kepler_processor.rb'

# TODO: use optparse to clean this up

# abort the execution if no filename is provided as an argument with the program call
Kernel.abort "Please pass the input filename as an argument! Use -f to force overwrite." if ARGV.size < 1
possible_methods = { "convert" => KeplerProcessor::Convertor, "transform" => KeplerProcessor::Transformer }
method = ARGV.delete_at 0

force_overwrite = false
if ARGV.first == "-f" # the zeroth element of ARGV, equivalent of ARGV[0]
  force_overwrite = true
  ARGV.delete_at 0 # remove the -f because it's not a filename we want to convert
end

ARGV.each do |filename|
  begin
    possible_methods[method].new(filename, force_overwrite).run
  rescue KeplerProcessor::FileExistsError
    puts "Your output file (#{filename}) already exists, please remove it first (or something)."
  end
end

#!/usr/bin/env ruby
require 'optparse'
require_relative 'kepler_processor.rb'

options = {:input_path => [], :output_path => "data/output"}

option_parser = OptionParser.new do |opts|
  opts.banner = "Usage: ruby run.rb -c command -i path_to_input_file [-o output_directory]"
  opts.on("-c", "--command COMMAND", String, "Specify the command to run") do |c|
    options[:command] = c
  end
  opts.on("-f", "--[no-]force_overwrite", "Force overwrite existing output files") do |f|
    options[:force_overwrite] = f
  end
  opts.on("-i", "--input PATH", Array, "Specify the path to the input file") do |p|
    options[:input_path] = p
  end
  opts.on("-o", "--output PATH", String, "Specify the path to the output directory. Defaults to data/output") do |p|
    options[:output_path] = p
  end
  opts.on_tail("-h", "--help", "Show this message") do
    puts opts
    exit
  end
end

begin
  option_parser.parse!
rescue
  puts $! # print out error
  option_parser.parse('--help') # print out command glossary
end

possible_methods = { "convert" => KeplerProcessor::Convertor, "transform" => KeplerProcessor::Transformer }
method_class = possible_methods[options[:command]]

options[:input_path].each do |filename|
  begin
    method_class.new(filename, options[:force_overwrite]).run
  rescue KeplerProcessor::FileExistsError
    puts "Your output file (#{filename}) already exists, please remove it first (or something)."
  end
end

Switch to using optparse for command line option parsing
Switch to using optparse for command line option parsing