#!/usr/bin/env ruby require 'optparse' options = { :delimiter => "\t", :interval => 1, :mode => :stat } OptionParser.new(ARGV) {|opt| opt.banner = "tail -f access.log | #{$0} " opt.on('-f [field]', Integer, 'value field') {|v| options[:field] = v - 1 } opt.on('-d [delimiter]', String) {|v| options[:delimiter] = v } opt.on('-i [interval]', Integer, 'interval for stat mode') {|v| options[:interval] = v } opt.on('-e [filter]', String) {|v| options[:filter] = v } opt.on('--stat', 'statistics mode (default)') { options[:mode] = :stat } opt.on('--print', 'print line mode') { options[:mode] = :print } }.parse! $: << File.expand_path('../../lib', __FILE__) require "tailstrom/command/#{options[:mode]}" cls = Module.const_get "Tailstrom::Command::#{options[:mode].capitalize}" cmd = cls.new options cmd.run