Mercurial > lasercutter
comparison 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 |
comparison
equal
deleted
inserted
replaced
10:ef7dbbd6452c | 11:f952052e37b7 |
---|---|
1 require 'optparse' | |
2 | |
3 class Graster | |
4 class Runner | |
5 | |
6 attr_reader :options, :args, :opts | |
7 | |
8 def initialize(args) | |
9 @args = args | |
10 @options = { :default_config_file => true } | |
11 @opts = OptionParser.new do |opts| | |
12 opts.banner = "Usage: graster [options] image" | |
13 | |
14 opts.on "-c", "--config FILE", "Use specified configuration file.", | |
15 "The default is ./graster.yml" do |c| | |
16 @options[:config_file] = c | |
17 end | |
18 | |
19 opts.on "-g", "--generate", "generate a configuration file with","defaults" do | |
20 @options[:generate_config] = true | |
21 end | |
22 | |
23 opts.on "-d", "--debug", "Dump useless debug info" do | |
24 @options[:debug] = true | |
25 end | |
26 | |
27 Graster::OPTIONS.each do |key,info| | |
28 type,sym,*desc = info | |
29 | |
30 if type.is_a? Array | |
31 cast = type[0].name.intern | |
32 type = Array | |
33 else | |
34 cast = type.name.intern | |
35 end | |
36 | |
37 opts.on "--#{key.to_s.gsub /_/, '-'} #{sym}", type, *desc do |x| | |
38 @options[:config] ||= {} | |
39 if type == Array | |
40 x = x.map {|s| Kernel.send(cast,s) } | |
41 else | |
42 x = Kernel.send(cast,x) | |
43 end | |
44 | |
45 @options[:config][key] = x | |
46 end | |
47 end | |
48 end | |
49 | |
50 @opts.parse!(args) | |
51 end | |
52 | |
53 def start! | |
54 if @options[:generate_config] | |
55 print Graster.new(@options).config_to_yaml | |
56 else | |
57 unless options[:image_file] = args.shift | |
58 puts @opts | |
59 exit 1 | |
60 end | |
61 | |
62 Graster.new(options).generate_all_files | |
63 end | |
64 end | |
65 end | |
66 end |