Sha256: 79b88cd7e595f9cea7026ec555ed505c5836a44f4916d7eed7923b9141063d12

Contents?: true

Size: 1.55 KB

Versions: 2

Compression:

Stored size: 1.55 KB

Contents

require 'optparse'

module RedisMonitor
  class CommandLineParser
    DEFAULTS = {
      http_server: 'webrick',
      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 redis-host',  'specify redis host (default is localhost)') do |val|
          arguments[:redis_host] = val
        end
        op.on('--port redis-port',  'specify redis port (default is 6379)') do |val|
          arguments[:redis_port] = val.to_i
        end
        op.on('--editable',  'the content will be editable (default is editable)') do |val|
          arguments[:permissions] ||= {}
          arguments[:permissions][:remove_content] = true
        end
        op.on('--not-editable',  'the content will be not editable (default is editable)') do |val|
          arguments[:permissions] ||= {}
          arguments[:permissions][:remove_content] = false
        end
        op.on('--credentials credentials',  'access only with credentials (format user:password)') do |val|
          user, password = val.to_s.split(':')
          arguments[:credentials] = {user: user, password: password}
        end
      end
      parser.parse!(argv)

      arguments
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
redis_monitor-0.1 lib/server/command_line_parser.rb
redis_monitor-0.0.6 lib/server/command_line_parser.rb