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.33.6 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.33.5 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.33.4 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.33.3 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.33.2 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.33.1 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.33.0 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.32.30 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.32.28 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.32.27 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.32.26 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.32.25 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.32.24 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.32.23 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.32.22 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.32.21 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.32.20 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.32.18 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.32.17 lib/rbbt/util/simpleopt/get.rb
rbbt-util-5.32.16 lib/rbbt/util/simpleopt/get.rb