Sha256: 451a1f7dbed3907121693b38cbdff85af416dfb274129bd0e2466c29ebe6a737

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

require 'fallen'

module Woodchuck::Runner
  extend Fallen
  # extend Fallen::CLI
  extend self
  
  def logger
    @logger ||=  Woodchuck::Logger.new(STDOUT)
  end
  
  def logger=(log)
    @logger = log
  end
    
  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
      opts.on('-f', '--format [FORMAT]', [:plain, :json_event], 'Input line format') do |input_format|
        options[:input_format] = input_format
      end
    end
    optparse.parse!(args)
    options
  end
  
  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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
woodchuck-json-event-0.0.2 lib/woodchuck/runner.rb
woodchuck-json-event-0.0.1 lib/woodchuck/runner.rb