class DRbQS::Command::OptionSetting

Attributes

setting[R]

Public Class Methods

new(help_message, setting) click to toggle source
# File lib/drbqs/command_line/option_setting.rb, line 6
def initialize(help_message, setting)
  @opt_parser = OptionParser.new(help_message)
  @setting = setting
end

Public Instance Methods

define(options = {}, &block) click to toggle source
# File lib/drbqs/command_line/option_setting.rb, line 23
def define(options = {}, &block)
  instance_eval(&block) if block_given?
  if options[:log_level]
    set(:log_level, '--log-level LEVEL', String,
        "Set the log level. The value accepts 'fatal', 'error', 'warn', 'info', and 'debug'. The default is 'error'.")
  end
  if options[:daemon]
    set(:daemon, '--daemon OUT', String, 'Execute as daemon and set output file for stdout and stderr.')
  end
  if options[:debug]
    set(:debug, '--debug', 'Set $DEBUG true.')
  end
end
parse!(argv) click to toggle source
# File lib/drbqs/command_line/option_setting.rb, line 37
def parse!(argv)
  @opt_parser.parse!(argv)
end
set(*args) { |opt_parser| ... } click to toggle source
# File lib/drbqs/command_line/option_setting.rb, line 11
def set(*args, &block)
  unless @setting
    raise "Not in method 'define'."
  end
  @opt_parser.on(*args[1..-1]) do |v|
    @setting.set(args[0], v)
    if block_given?
      yield(@opt_parser)
    end
  end
end