Sha256: 17f87de5d64e5cc86d62ca4b159eb924075c8db3814633244bd45b7206612c36

Contents?: true

Size: 1.83 KB

Versions: 3

Compression:

Stored size: 1.83 KB

Contents

#!/usr/bin/env ruby

require 'drbqs'
require 'optparse'

Version = '0.0.1'

help_message =<<HELP
Usage: #{File.basename(__FILE__)} <definition.rb> [other files ...] [options ...]
       #{File.basename(__FILE__)} <definition.rb> [other files ...] [options ...] -- [server options ...]
Start DRbQS server of definition files.

HELP

options = {
  :log_file => STDOUT
}

if n = ARGV.index('--')
  command_argv = ARGV[0..(n - 1)]
  server_argv = ARGV[(n + 1)..-1]
else
  command_argv = ARGV
  server_argv = []
end

begin
  OptionParser.new(help_message) do |opt|
    opt.on('-p PORT', '--port', Integer, 'Set the port number of server.') do |v|
      options[:port] = v
    end
    opt.on('--acl FILE', String, 'Set a file to define ACL.') do |v|
      options[:acl] = v
    end
    opt.on('--log-file STR', String, "Set the path of log file. If this options is not set, use STDOUT.") do |v|
      options[:log_file] = v
    end
    opt.on('--log-level LEVEL', String,
           "Set the log level. The value accepts 'fatal', 'error', 'warn', 'info', and 'debug'. The default is 'error'.") do |v|
      if /^(fatal)|(error)|(warn)|(info)|(debug)$/i =~ v
        options[:log_level] = eval("Logger::#{v.upcase}")
      else
        raise "Invalid log level."
      end
    end
    opt.on('--debug', 'Set $DEBUG true.') do |v|
      $DEBUG = true
    end
    opt.parse!(command_argv)
  end
rescue OptionParser::InvalidOption
  $stderr.print <<MES
error: Invalid Option
#{help_message}
MES
  exit(2)
rescue OptionParser::InvalidArgument
  $stderr.print <<MES
error: Invalid Argument
#{help_message}
MES
  exit(2)
end

if command_argv.size == 0 || !File.exist?(command_argv[0])
  raise "Invalid arguments. Please refer '#{File.basename(__FILE__)} -h'."
end

command_argv.each do |path|
  puts "load #{path}"
  load path
end

DRbQS.parse_option(server_argv)
DRbQS.start_server(options)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
drbqs-0.0.7 bin/drbqs-server
drbqs-0.0.6 bin/drbqs-server
drbqs-0.0.5 bin/drbqs-server