#!/usr/bin/env ruby $:.unshift File.expand_path('../../lib', File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__) require 'rubygems' unless Object.const_defined?(:Gem) require 'optparse' require "redis-browser" # Sinatra runtime options sinatra_options = { bind: '127.0.0.1', port: 4567 } redis_connection = {} OptionParser.new do |opts| opts.banner = "Usage: redis-browser [options]" opts.on("-C PATH", "--config PATH", "Path to YAML config file") do |v| require 'yaml' require 'erb' config = YAML.load(ERB.new(IO.read(v)).result) RedisBrowser.configure(config) end opts.on("-U URL", "--url URL", "Connection URL. Defaults to redis://127.0.0.1:6379/0") do |v| v = "redis://#{v}" unless v =~ /^redis:\/\// config = { 'connections' => { 'default' => v } } RedisBrowser.configure(config) end opts.on("-h HOSTNAME", "Default redis connection hostname") do |v| redis_connection['host'] = v end opts.on("-p PORT", "Default redis connection port") do |v| redis_connection['port'] = v end opts.on("-n DB", "Default redis connection database number") do |v| redis_connection['db'] = v end opts.on("-a PASSWORD", "Default redis connection password") do |v| redis_connection['auth'] = v end opts.on("-B ADDRESS", "--bind ADDRESS", "Server hostname or IP address to listen on") do |v| sinatra_options['bind'] = v end opts.on("-P PORT", "--port PORT", "Port number to listen on") do |v| sinatra_options['port'] = v end opts.on("-v", "--version", "Display version number") do puts RedisBrowser::VERSION exit end end.parse! unless redis_connection.empty? config = { 'connections' => { 'default' => redis_connection } } RedisBrowser.configure(config) end RedisBrowser::Web.run! sinatra_options