Sha256: d546741a856607f0ffec6c86c01cc0361877ff1635f2c186977b7efed82c1e1d

Contents?: true

Size: 1.51 KB

Versions: 51

Compression:

Stored size: 1.51 KB

Contents

module SOPT
  GOT_OPTIONS= IndiferentHash.setup({})
  def self.current_options=(options)
    @@current_options = options
  end
  def self.consume(args = ARGV)
    i = 0
    @@current_options ||= {}
    while i < args.length do
      current = args[i]
      break if current == "--"
      if m = current.match(/--?(.+?)(?:=(.+))?$/)
        key = $1
        value = $2

        input = inputs.include?(key)? key : shortcuts[key]

        if input.nil?
          i += 1
          next
        else
          args.delete_at i
        end
      else
        i += 1
        next
      end

      if input_types[input] == :string
        value = args.delete_at(i) if value.nil?
        @@current_options[input] = value
      else
        if value.nil? and %w(F false FALSE no).include?(args[i])
          Log.warn "Boolean values are best specified as #{current}=[true|false], not #{ current } [true|false]. Token '#{args[i]}' following '#{current}' automatically assigned as value" 
          value = args.delete_at(i)
        end
        @@current_options[input] = %w(F false FALSE no).include?(value)? false : true
      end
    end

    IndiferentHash.setup @@current_options
    GOT_OPTIONS.merge! @@current_options

    @@current_options
  end
  
  def self.get(opt_str)
    SOPT.parse(opt_str)
    SOPT.consume(ARGV)
  end

  def self.require(options, *parameters)
    parameters.flatten.each do |parameter|
      raise ParameterException, "Parameter '#{ Log.color :blue, parameter }' not given" if options[parameter].nil?
    end
  end
end

Version data entries

51 entries across 51 versions & 3 rubygems

Version Path
scout-gear-9.0.0 lib/scout/simple_opt/get.rb
scout-gear-8.1.0 lib/scout/simple_opt/get.rb
rbbt-util-5.38.1 lib/rbbt/util/simpleopt/get.rb
scout-gear-8.0.0 lib/scout/simple_opt/get.rb
scout-gear-7.3.0 lib/scout/simple_opt/get.rb
scout-gear-7.2.0 lib/scout/simple_opt/get.rb
scout-gear-7.1.0 lib/scout/simple_opt/get.rb
scout-gear-6.0.0 lib/scout/simple_opt/get.rb
scout-gear-5.2.0 lib/scout/simple_opt/get.rb
scout-gear-5.1.1 lib/scout/simple_opt/get.rb
rbbt-util-5.38.0 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.37.16 lib/rbbt/util/simpleopt/get.rb
scout-gear-2.0.0 lib/scout/simple_opt/get.rb
rbbt-util-5.37.15 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.37.14 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.37.13 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.37.12 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.37.11 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.37.10 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.37.9 lib/rbbt/util/simpleopt/get.rb