Sha256: 578903618ec1b2ca319b07e706dc1a6f227db2181b85568cc67aba19877e910e

Contents?: true

Size: 1.76 KB

Versions: 70

Compression:

Stored size: 1.76 KB

Contents

module Clamp
  module Option

    module Parsing

      protected

      def parse_options

        while remaining_arguments.first =~ /\A-/

          switch = remaining_arguments.shift
          break if switch == "--"

          case switch
          when /\A(-\w)(.+)\z/m # combined short options
            switch = $1
            if find_option(switch).flag?
              remaining_arguments.unshift("-" + $2)
            else
              remaining_arguments.unshift($2)
            end
          when /\A(--[^=]+)=(.*)\z/m
            switch = $1
            remaining_arguments.unshift($2)
          end

          option = find_option(switch)
          value = option.extract_value(switch, remaining_arguments)

          begin
            option.of(self).take(value)
          rescue ArgumentError => e
            signal_usage_error "option '#{switch}': #{e.message}"
          end

        end

        # Fill in gap from environment
        self.class.recognised_options.each do |option|
          option.of(self).default_from_environment
        end

        # Verify that all required options are present
        self.class.recognised_options.each do |option|
          # If this option is required and the value is nil, there's an error.
          if option.required? and send(option.attribute_name).nil?
            message = "option '#{option.switches.first}'"
            if option.environment_variable
              message += " (or env #{option.environment_variable})"
            end
            message += " is required"
            signal_usage_error message
          end
        end
      end

      private

      def find_option(switch)
        self.class.find_option(switch) ||
        signal_usage_error("Unrecognised option '#{switch}'")
      end

    end

  end
end

Version data entries

70 entries across 66 versions & 18 rubygems

Version Path
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/parsing.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/parsing.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/parsing.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/parsing.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/parsing.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/parsing.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/parsing.rb
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/parsing.rb
logstash-output-scalyr-0.1.21.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/parsing.rb
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/parsing.rb
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/parsing.rb
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/parsing.rb
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/parsing.rb
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/parsing.rb
logstash-output-scalyr-0.1.15.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/parsing.rb
logstash-output-scalyr-0.1.14.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/parsing.rb
logstash-output-scalyr-0.1.13 vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/parsing.rb
logstash-output-scalyr-0.1.12 vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/parsing.rb
logstash-output-scalyr-0.1.11.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/parsing.rb
logstash-output-scalyr-0.1.10.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/parsing.rb