Sha256: 14aac168e2ba9330ab1e5c23422d154b9a9bfcde0a08f16a956e0e188e6dd817

Contents?: true

Size: 1.82 KB

Versions: 4

Compression:

Stored size: 1.82 KB

Contents

#!/usr/bin/ruby

# = Redis-Dump
# 
#
# Usage:
# 
#     $ redis-load -h
#     $ <dumpfile_full.json redis-load
#     $ <dumpfile_db15.json redis-load -d 15
#
#--

RD_HOME = File.expand_path File.join(File.dirname(__FILE__), '..')
lib_dir = File.join(RD_HOME, 'lib')
$:.unshift lib_dir  

require 'redis/dump'
require 'drydock'

# Command-line interface for bin/redis-dump
class Redis::Dump::CLI
  extend Drydock
  
  default :load
  trawler :load
  
  global :u, :uri, String, "Redis URI (e.g. redis://hostname[:port])"
  global :d, :database, Integer, "Redis database (e.g. -d 15)"
  global :V, :version, "Display version" do 
    puts "Version: #{Redis::Dump::VERSION.to_s}"
    exit 0
  end
  global :D, :debug do
    Redis::Dump.debug = true
  end
  global :nosafe do
    Redis::Dump.safe = false
  end
  
  before do |obj|
    obj.global.uri ||= 'redis://%s:%s' % [Redis::Dump.host, Redis::Dump.port]
    obj.global.uri = 'redis://' << obj.global.uri unless obj.global.uri.match(/^redis:\/\//)
    obj.global.database &&= obj.global.database.to_i
    obj.global.database ||= (0..15)
    Redis::Dump.ld " redis_uri: #{obj.global.uri} (#{obj.global.database})"
  end
  
  usage "<dumpfile_full.json redis-load"
  usage "<dumpfile_db15.json redis-load -d 15"
  command :load do |obj|
    rd = Redis::Dump.new obj.global.database, obj.global.uri
    rd.load STDIN
  end
  
end

  
begin
  Drydock.run!(ARGV, STDIN) if Drydock.run? && !Drydock.has_run?
rescue Drydock::ArgError, Drydock::OptError => ex
  STDERR.puts ex.message
  STDERR.puts ex.usage
rescue Drydock::InvalidArgument => ex
  STDERR.puts ex.message
rescue Drydock::UnknownCommand => ex
  STDERR.puts "Unknown command: %s" % ex.name
rescue Interrupt
  puts $/, "Exiting... "
  exit 1
rescue => ex
  STDERR.puts "ERROR (#{ex.class.to_s}): #{ex.message}"
  STDERR.puts ex.backtrace if Redis::Dump.debug
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
redis-dump-0.1.5 bin/redis-load
redis-dump-0.1.4 bin/redis-load
redis-dump-0.1.3 bin/redis-load
redis-dump-0.1.2 bin/redis-load