Sha256: 1cfe77fcd6f17d12c11775b06476f74a712818f2a1c623aa7a2b5087e33acf77

Contents?: true

Size: 1.55 KB

Versions: 1

Compression:

Stored size: 1.55 KB

Contents

#!/usr/bin/env ruby
# encoding: utf-8
# Author: kimoto
require 'vrowser'
require 'optparse'
require 'vrowser/http_daemon'
require 'fileutils'

options = {}
parser = OptionParser.new{ |opts|
  opts.banner = "Usage: #{File.basename($0)}"
  opts.on("-f", "--config-file=PATH", "specify config file"){ |v|
    options[:config_path] = v
  }

  opts.on("-h", "--host=HOST", "host"){ |v| options[:host] = v }
  opts.on("-p", "--port=PORT", "port"){ |v| options[:port] = v }
  opts.on("-r", "--document-root=PATH", "root"){ |v| options[:document_root] = v }

}
parser.parse!

if ARGV.first == "sample"
  p sample_config = File.expand_path(File.join(File.dirname(__FILE__), "../examples/config.yml"))
  FileUtils.cp(sample_config, "./config.yml", :verbose => true)
  exit(0)
end

if options[:config_path].nil?
  parser.help.display
  exit(1)
end

Vrowser.load_file(options[:config_path]) do |vrowser|
  case sub_command = ARGV.shift
  when "fetch"
    vrowser.fetch
  when "update"
    vrowser.update
    vrowser.clear
  when "list"
    puts vrowser.servers.map(&:name).join($/)
  when "json"
    vrowser.active_servers.select(:name, :host, :ping, :num_players, :type, :map, :players).order(:host).map(&:values).to_json.display
  when "daemon"
    unless options[:host] and options[:port] and options[:document_root]
      raise ArgumentError
    end

    Vrowser::HTTPDaemon.start(
      :Host => options[:host],
      :Port => options[:port],
      :DocumentRoot => options[:document_root],
      :config_path => options[:config_path])
  else
    raise ArgumentError(sub_command)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vrowser-0.0.5 bin/vrowser