Sha256: c727f34f5acfb926f95571b0995e8bf740c45a8c41ccc6fe6ad8b5aae07db3e4

Contents?: true

Size: 1.46 KB

Versions: 74

Compression:

Stored size: 1.46 KB

Contents

require 'clamp/attribute/declaration'
require 'clamp/option/definition'

module Clamp
  module Option

    module Declaration

      include Clamp::Attribute::Declaration

      def option(switches, type, description, opts = {}, &block)
        Option::Definition.new(switches, type, description, opts).tap do |option|
          declared_options << option
          block ||= option.default_conversion_block
          define_accessors_for(option, &block)
        end
      end

      def find_option(switch)
        recognised_options.find { |o| o.handles?(switch) }
      end

      def declared_options
        @declared_options ||= []
      end

      def recognised_options
        declare_implicit_options
        effective_options
      end

      private

      def declare_implicit_options
        return nil if defined?(@implicit_options_declared)
        unless effective_options.find { |o| o.handles?("--help") }
          help_switches = ["--help"]
          help_switches.unshift("-h") unless effective_options.find { |o| o.handles?("-h") }
          option help_switches, :flag, "print help" do
            request_help
          end
        end
        @implicit_options_declared = true
      end

      def effective_options
        ancestors.inject([]) do |options, ancestor|
          if ancestor.kind_of?(Clamp::Option::Declaration)
            options + ancestor.declared_options
          else
            options
          end
        end
      end

    end

  end
end

Version data entries

74 entries across 70 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/declaration.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/declaration.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/declaration.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/declaration.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/declaration.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/declaration.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/declaration.rb
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/declaration.rb
logstash-output-scalyr-0.1.21.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/declaration.rb
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/declaration.rb
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/declaration.rb
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/declaration.rb
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/declaration.rb
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/declaration.rb
logstash-output-scalyr-0.1.15.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/declaration.rb
logstash-output-scalyr-0.1.14.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/declaration.rb
logstash-output-scalyr-0.1.13 vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/declaration.rb
logstash-output-scalyr-0.1.12 vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/declaration.rb
logstash-output-scalyr-0.1.11.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/declaration.rb
logstash-output-scalyr-0.1.10.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/option/declaration.rb