Class: Graster::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/graster/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Runner

Returns a new instance of Runner.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/graster/runner.rb', line 8

def initialize(args)
  @args = args
  @options = { :default_config_file => true }
  @opts = OptionParser.new do |opts|
    opts.banner = "Usage: graster [options] image"

    opts.on "-c", "--config FILE", "Use specified configuration file.",
                                   "The default is ./graster.yml" do |c|
      @options[:config_file] = c
    end

    opts.on "-g", "--generate", "generate a configuration file with","defaults" do
      @options[:generate_config] = true
    end

    opts.on "-d", "--debug", "Dump useless debug info" do
      @options[:debug] = true
    end

    Graster::OPTIONS.each do |key,info|
      type,sym,*desc = info

      if type.is_a? Array
        cast = type[0].name.intern
        type = Array
      else
        cast = type.name.intern
      end

      opts.on "--#{key.to_s.gsub /_/, '-'} #{sym}", type, *desc do |x|
        @options[:config] ||= {}
        if type == Array
          x = x.map {|s| Kernel.send(cast,s) }
        else
          x = Kernel.send(cast,x)
        end

        @options[:config][key] = x
      end
    end
  end

  @opts.parse!(args)
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



6
7
8
# File 'lib/graster/runner.rb', line 6

def args
  @args
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/graster/runner.rb', line 6

def options
  @options
end

#optsObject (readonly)

Returns the value of attribute opts.



6
7
8
# File 'lib/graster/runner.rb', line 6

def opts
  @opts
end

Instance Method Details

#start!Object



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/graster/runner.rb', line 53

def start!
  if @options[:generate_config]
    print Graster.new(@options).config_to_yaml
  else
    unless options[:image_file] = args.shift
      puts @opts
      exit 1
    end

    Graster.new(options).generate_all_files
  end
end