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