Sha256: e64a03b5344904d869e54210f00e768cfe2e50346ffd423105524e34b5b1b62f

Contents?: true

Size: 920 Bytes

Versions: 4

Compression:

Stored size: 920 Bytes

Contents

require 'optparse'

module RedisMonitor
  class CommandLineParser
    DEFAULTS = {
      http_server: 'thin',
      http_port: 6369,
      redis_host: 'localhost',
      redis_port: 6379,
    }

    def self.parse(argv)
      arguments = DEFAULTS.dup

      parser = OptionParser.new do |op|
        op.on('--http-server server', 'specify rack server/handler (default is thin)') do |val|
          arguments[:http_server] = val
        end
        op.on('--http-port port',  'specify http port (default is 6369)') do |val|
          arguments[:http_port] = val.to_i
        end
        op.on('--host host',  'specify redis host (default is localhost)') do |val|
          arguments[:redis_host] = val
        end
        op.on('--port port',  'specify redis port (default is 6379)') do |val|
          arguments[:redis_port] = val.to_i
        end
      end
      parser.parse!(argv)

      arguments
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
redis_monitor-0.0.5 lib/server/command_line_parser.rb
redis_monitor-0.0.4 lib/server/command_line_parser.rb
redis_monitor-0.0.3 lib/server/command_line_parser.rb
redis_monitor-0.0.2 lib/server/command_line_parser.rb