Mercurial > lasercutter
view graster/graster/lib/graster/runner.rb @ 11:f952052e37b7
trying a fix.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 24 Aug 2010 19:06:45 -0400 |
parents | |
children |
line wrap: on
line source
1 require 'optparse'3 class Graster4 class Runner6 attr_reader :options, :args, :opts8 def initialize(args)9 @args = args10 @options = { :default_config_file => true }11 @opts = OptionParser.new do |opts|12 opts.banner = "Usage: graster [options] image"14 opts.on "-c", "--config FILE", "Use specified configuration file.",15 "The default is ./graster.yml" do |c|16 @options[:config_file] = c17 end19 opts.on "-g", "--generate", "generate a configuration file with","defaults" do20 @options[:generate_config] = true21 end23 opts.on "-d", "--debug", "Dump useless debug info" do24 @options[:debug] = true25 end27 Graster::OPTIONS.each do |key,info|28 type,sym,*desc = info30 if type.is_a? Array31 cast = type[0].name.intern32 type = Array33 else34 cast = type.name.intern35 end37 opts.on "--#{key.to_s.gsub /_/, '-'} #{sym}", type, *desc do |x|38 @options[:config] ||= {}39 if type == Array40 x = x.map {|s| Kernel.send(cast,s) }41 else42 x = Kernel.send(cast,x)43 end45 @options[:config][key] = x46 end47 end48 end50 @opts.parse!(args)51 end53 def start!54 if @options[:generate_config]55 print Graster.new(@options).config_to_yaml56 else57 unless options[:image_file] = args.shift58 puts @opts59 exit 160 end62 Graster.new(options).generate_all_files63 end64 end65 end66 end