Class: GoshrineBot::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/goshrine_bot/runner.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRunner

Returns a new instance of Runner.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/goshrine_bot/runner.rb', line 15

def initialize
  # defaults
  self.options = {
    :server_url => "http://goshrine.com/",
    :gtp_cmd_line => "gnugo --mode gtp",
    :debug => false,
    :idle_shutdown_timeout => 60,
    :maximum_concurrent_games => nil,
    :pid_path => "./goshrine_bot.pid"
  }
  
  cmd_line_options = parse_options
  
  if !File.exists?(config_path)
    puts "You must generate a config file."
    exit
  end
  
  config = YAML::load(ERB.new(IO.read(config_path)).result)
  #puts "config = #{config.inspect}"
  bot_name = ARGV[0] || config.keys.first
  #puts "bot_name = #{ARGV[0]}"
  if config[bot_name].nil?
    puts "No config found for #{bot_name.inspect}"
    exit
  end
  options.merge!(config[bot_name])
  #puts "Options = #{options.inspect}"
  options[:bot_name] = bot_name
  
  start
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/goshrine_bot/runner.rb', line 7

def options
  @options
end

Class Method Details

.runObject



10
11
12
# File 'lib/goshrine_bot/runner.rb', line 10

def run
  self.new
end

Instance Method Details

#config_pathObject



48
49
50
# File 'lib/goshrine_bot/runner.rb', line 48

def config_path
  options[:config_path] || "./goshrine_bot.yml"
end

#parse_optionsObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/goshrine_bot/runner.rb', line 59

def parse_options
  OptionParser.new do |opts|
    opts.summary_width = 25
    opts.banner = "GoShrineBot (1.0)\n\n",
                  "Usage: goshrine_bot [-c configfile] [bot_name]\n",
                  "       goshrine_bot --help\n"
    
    opts.separator ""
    opts.separator ""; opts.separator "Configuration:"
    
    opts.on("-c", "--config FILE", String, "Path to configuration file.", "(default: #{options[:config_path]})") do |v|
      options[:config_path] = File.expand_path(v)
    end
    
    opts.separator ""; opts.separator "Miscellaneous:"
    
    opts.on_tail("-?", "--help", "Display this usage information.") do
      puts "#{opts}\n"
      exit
    end
    
  end.parse!
  options
end

#startObject



52
53
54
55
56
57
# File 'lib/goshrine_bot/runner.rb', line 52

def start
  puts "Starting GoShrine (v#{GoshrineBot::VERSION}) bot client: #{options[:bot_name]}."
  
  client = Client.new(options)
  client.run      
end