Sha256: 439142229f228e345b95c2696978945b92c80f8b6e56d53267634108bece3380

Contents?: true

Size: 1.12 KB

Versions: 7

Compression:

Stored size: 1.12 KB

Contents

module DRbQS
  class Command
    class OptionSetting
      attr_reader :setting

      def initialize(help_message, setting)
        @opt_parser = OptionParser.new(help_message)
        @setting = setting
      end

      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

      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

      def parse!(argv)
        @opt_parser.parse!(argv)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
drbqs-0.1.1 lib/drbqs/command_line/option_setting.rb
drbqs-0.1.0 lib/drbqs/command_line/option_setting.rb
drbqs-0.0.19 lib/drbqs/command_line/option_setting.rb
drbqs-0.0.18 lib/drbqs/command_line/option_setting.rb
drbqs-0.0.17 lib/drbqs/command_line/option_setting.rb
drbqs-0.0.16 lib/drbqs/command_line/option_setting.rb
drbqs-0.0.15 lib/drbqs/command_line/option_setting.rb