Sha256: 63fd32ae008de22217ccf8889d0508717e34d20d67e72f90c2a584869fd82905

Contents?: true

Size: 1.37 KB

Versions: 306

Compression:

Stored size: 1.37 KB

Contents

module SOPT
  GOT_OPTIONS= IndiferentHash.setup({})
  def self.consume(args = ARGV)
    i = 0
    values = {}
    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?
        values[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
        values[input] = %w(F false FALSE no).include?(value)? false : true
      end
    end

    IndiferentHash.setup values
    GOT_OPTIONS.merge! values

    values
  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

306 entries across 306 versions & 1 rubygems

Version Path
rbbt-util-5.34.27 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.34.26 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.34.25 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.34.24 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.34.23 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.34.22 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.34.21 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.34.20 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.34.18 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.34.17 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.34.16 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.34.15 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.34.14 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.34.13 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.34.12 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.34.11 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.34.10 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.34.9 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.34.8 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.34.7 lib/rbbt/util/simpleopt/get.rb