Sha256: ee9b03b3c3c5e18e6c8300b04f652c824eaaf8dc287d06748df2a5f0bbe661f5

Contents?: true

Size: 1.92 KB

Versions: 10

Compression:

Stored size: 1.92 KB

Contents

require 'clamp'
require 'logstash/environment'

module Clamp
  module Attribute
    class Instance
      def default_from_environment
        # we don't want uncontrolled var injection from the environment
        # since we're establishing that settings can be pulled from only three places:
        # 1. default settings
        # 2. yaml file
        # 3. cli arguments
      end
    end
  end

  module Option

    module StrictDeclaration

      include Clamp::Attribute::Declaration

      # Instead of letting Clamp set up accessors for the options
      # weŕe going to tightly controlling them through
      # LogStash::SETTINGS
      def define_simple_writer_for(option, &block)
        LogStash::SETTINGS.get(option.attribute_name)
        define_method(option.write_method) do |value|
          value = instance_exec(value, &block) if block
          LogStash::SETTINGS.set_value(option.attribute_name, value)
        end
      end

      def define_reader_for(option)
        define_method(option.read_method) do
          LogStash::SETTINGS.get_value(option.attribute_name)
        end
      end

    end

    class Definition
      # Allow boolean flags to optionally receive a true/false argument
      # to explicitly set them, i.e.
      # --long.flag.name       => sets flag to true
      # --long.flag.name true  => sets flag to true
      # --long.flag.name false => sets flag to false
      # --long.flag.name=true  => sets flag to true
      # --long.flag.name=false => sets flag to false
      def extract_value(switch, arguments)
        if flag? && (arguments.first.nil? || arguments.first.match("^-"))
          flag_value(switch)
        else
          arguments.shift
        end
      end
    end
  end

  # Create a subclass of Clamp::Command that enforces the use of
  # LogStash::SETTINGS for setting validation
  class StrictCommand < Command
    class << self
      include ::Clamp::Option::StrictDeclaration
    end
  end
end


Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
logstash-core-5.0.0.alpha5.snapshot1-java lib/logstash/patches/clamp.rb
logstash-core-5.0.0.alpha4.snapshot3-java lib/logstash/patches/clamp.rb
logstash-core-5.0.0.alpha4.snapshot2-java lib/logstash/patches/clamp.rb
logstash-core-5.0.0.alpha4.snapshot1-java lib/logstash/patches/clamp.rb
logstash-core-5.0.0.alpha3-java lib/logstash/patches/clamp.rb
logstash-core-5.0.0.alpha3.snapshot8-java lib/logstash/patches/clamp.rb
logstash-core-5.0.0.alpha3.snapshot7-java lib/logstash/patches/clamp.rb
logstash-core-5.0.0.alpha3.snapshot6-java lib/logstash/patches/clamp.rb
logstash-core-5.0.0.alpha3.snapshot5-java lib/logstash/patches/clamp.rb
logstash-core-5.0.0.alpha3.snapshot4-java lib/logstash/patches/clamp.rb