Module: Woodchuck::Runner

Extended by:
Fallen, Runner
Included in:
Runner
Defined in:
lib/woodchuck/runner.rb

Instance Method Summary collapse

Instance Method Details

#loggerObject



8
9
10
# File 'lib/woodchuck/runner.rb', line 8

def logger
  @logger ||=  Woodchuck::Logger.new(STDOUT)
end

#logger=(log) ⇒ Object



12
13
14
# File 'lib/woodchuck/runner.rb', line 12

def logger=(log)
  @logger = log
end

#read(args = ARGV) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/woodchuck/runner.rb', line 16

def read(args=ARGV)
  options = {}

  optparse = OptionParser.new do |opts|
    opts.on('-l', '--log-level [LOG_LEVEL]', [:debug, :warn, :info, :error, :fatal], 'set the log level') do |level|
      options[:log_level] = level.to_sym
    end
    opts.on('-o', '--output [OUTPUT]', 'set the output') do |output|
      options[:output] = output.to_sym
    end
    opts.on('-p', '--paths [PATHS]', Array, 'A list of file paths to watch') do |paths|
      options[:paths] = paths
    end
  end
  optparse.parse!(args)
  options
end

#run(options = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/woodchuck/runner.rb', line 34

def run(options={})
  puts options.inspect
  agent = Woodchuck::Agent.new(options)
  agent.start(true)
  Signal.trap('INT') do
    @logger.warn :signal => signal
    agent.stop
    exit 0
  end    
end