Sha256: 56af81a80a203464c4960efd3272dc0837ff82b83b98dba71f190dc9dc14352d

Contents?: true

Size: 1.83 KB

Versions: 3

Compression:

Stored size: 1.83 KB

Contents

#!/usr/bin/env ruby

File.expand_path("../../lib", __FILE__).tap do |lib|
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
end

require "optparse"

require "socrates"
require "socrates/sample_states"

options = {
  adapter: "console",
  storage: "memory",
  debug:   false
}

option_parser = OptionParser.new do |parser|
  parser.banner = "Usage: socrates [options] run"

  parser.on("-h", "--help", "Show this help message") do
    puts parser
    exit
  end
  parser.on("-a", "--adapter ADAPTER", "Use the specified Adapter: console (default) or slack") do |value|
    options[:adapter] = value.downcase
  end
  parser.on("-s", "--storage STORAGE", "Use the specified Storage: memory (default) or redis") do |value|
    options[:storage] = value.downcase
  end
  parser.on("-d", "--debug", "Print detailed logging") do
    options[:debug] = true
  end
end
option_parser.parse!

def run_command(options)
  storage =
    case options[:storage]
      when "redis"
        Socrates::Storage::RedisStorage.new(url: ENV.fetch("REDIS_URL", "redis://localhost"))
      else
        Socrates::Storage::MemoryStorage.new
    end

  Socrates.configure do |config|
    config.storage = storage

    if options[:debug]
      config.logger       = Socrates::Logger.default
      config.logger.level = Logger::DEBUG
    end
  end

  case (adapter = options[:adapter])
    when "console"
      Socrates::Bots::CLIBot.new(state_factory: Socrates::SampleStates::StateFactory.new).start
    when "slack"
      Socrates::Bots::SlackBot.new(state_factory: Socrates::SampleStates::StateFactory.new).start
    else
      puts "Unknown adapter '#{adapter}'"
      exit 1
  end
end

command = ARGV.shift

if command.nil?
  puts option_parser.help
  exit 1
end

case command.downcase
  when "run"
    run_command(options)
  else
    puts "Unknown command '#{command}'"
    exit 1
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
socrates-0.1.7 exe/socrates
socrates-0.1.6 exe/socrates
socrates-0.1.4 exe/socrates