Sha256: 0fca26bed1ba3e2065ee881475c64cc934d0dad8de06ab44bf49003a9164c01d

Contents?: true

Size: 774 Bytes

Versions: 4

Compression:

Stored size: 774 Bytes

Contents

module RedisRing

  class CLI

    COMMANDS = [:help, :start]

    attr_reader :argv

    def initialize(argv)
      @argv = argv
    end

    def run
      command = argv[0]
      if command.nil? || !COMMANDS.include?(command.to_sym)
        usage
        exit(1)
      else
        send(command, *argv[1..-1])
        exit(0)
      end
    end

    protected

    def help
      usage
    end

    def usage
      puts <<USAGE
Usage:
  #{$0} command [arguments]

Commands:
  help - prints this message

  start [config_file] - starts application
USAGE
    end

    def start(config_file = nil)
      config = config_file ? Configuration.from_yml_file(config_file) : Configuration.new

      app = Application.new(config)
      app.start
      app.wait
    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
redis_ring-0.1.3 lib/redis_ring/cli.rb
redis_ring-0.1.2 lib/redis_ring/cli.rb
redis_ring-0.1.1 lib/redis_ring/cli.rb
redis_ring-0.1.0 lib/redis_ring/cli.rb