lib/configliere/commandline.rb
def process_argv!
      args = ARGV.dup
      self.rest = []
      @unknown_argvs = []
      until args.empty? do
        arg = args.shift
        case
        # end of options parsing
        when arg == '--'
          self.rest += args
          break
        # --param=val or --param
        when arg =~ /\A--([\w\-\.]+)(?:=(.*))?\z/
          param, val = [$1, $2]
          warn "Configliere uses _underscores not dashes for params" if param.include?('-')
          @unknown_argvs << param.to_sym if (not has_definition?(param))
          self[param] = parse_value(val)
        # -abc
        when arg =~ /\A-(\w\w+)\z/
          $1.each_char do |flag|
            param = find_param_for_flag(flag)
            unless param then @unknown_argvs << flag ; next ; end
            self[param] = true
          end
        # -a val
        when arg =~ /\A-(\w)\z/
          flag = find_param_for_flag($1)
          unless flag then @unknown_argvs << flag ; next ; end
          if (not args.empty?) && (args.first !~ /\A-/)
            val = args.shift
          else
            val = nil
          end
          self[flag] = parse_value(val)
        # -a=val
        when arg =~ /\A-(\w)=(.*)\z/
          flag, val = [find_param_for_flag($1), $2]
          unless flag then @unknown_argvs << flag ; next ; end
          self[flag] = parse_value(val)
        else
          self.rest << arg
        end
      end
      @unknown_argvs.uniq!
    end
#
# Parse the command-line args into the params hash.
#
# '--happy_flag'   produces :happy_flag => true in the params hash
# '--foo=foo_val'  produces :foo => 'foo_val' in the params hash.
# '--'             Stop parsing; all remaining args are piled into :rest
#
# self.rest        contains all arguments that don't start with a '--'
#                  and all args following the '--' sentinel if any.
#
Parse the command-line args into the params hash.


Parse the command - line args into the params hash .
def process_argv!
      args = ARGV.dup
      self.rest = []
      @unknown_argvs = []
      until args.empty? do
        arg = args.shift
        case
        when arg == '--'
          self.rest += args
          break
        when arg =~ /\A--([\w\-\.]+)(?:=(.*))?\z/
          param, val = [$1, $2]
          warn "Configliere uses _underscores not dashes for params" if param.include?('-')
          @unknown_argvs << param.to_sym if (not has_definition?(param))
          self[param] = parse_value(val)
        when arg =~ /\A-(\w\w+)\z/
          $1.each_char do |flag|
            param = find_param_for_flag(flag)
            unless param then @unknown_argvs << flag ; next ; end
            self[param] = true
          end
        when arg =~ /\A-(\w)\z/
          flag = find_param_for_flag($1)
          unless flag then @unknown_argvs << flag ; next ; end
          if (not args.empty?) && (args.first !~ /\A-/)
            val = args.shift
          else
            val = nil
          end
          self[flag] = parse_value(val)
        when arg =~ /\A-(\w)=(.*)\z/
          flag, val = [find_param_for_flag($1), $2]
          unless flag then @unknown_argvs << flag ; next ; end
          self[flag] = parse_value(val)
        else
          self.rest << arg
        end
      end
      @unknown_argvs.uniq!
    end
def process_argv! args = ARGV . dup self . rest = [ ] @unknown_argvs = [ ] until args . empty? do arg = args . shift case when arg == '--' self . rest += args break when arg =~ / \A --([ \w \- \. ]+)(?:=(.*))? \z / param , val = [ $1 , $2 ] warn "Configliere uses _underscores not dashes for params" if param . include? ( '-' ) @unknown_argvs << param . to_sym if ( not has_definition? ( param ) ) self [ param ] = parse_value ( val ) when arg =~ / \A -( \w \w +) \z / $1 . each_char do | flag | param = find_param_for_flag ( flag ) unless param then @unknown_argvs << flag ; next ; end self [ param ] = true end when arg =~ / \A -( \w ) \z / flag = find_param_for_flag ( $1 ) unless flag then @unknown_argvs << flag ; next ; end if ( not args . empty? ) && ( args . first !~ / \A - / ) val = args . shift else val = nil end self [ flag ] = parse_value ( val ) when arg =~ / \A -( \w )=(.*) \z / flag , val = [ find_param_for_flag ( $1 ) , $2 ] unless flag then @unknown_argvs << flag ; next ; end self [ flag ] = parse_value ( val ) else self . rest << arg end end @unknown_argvs . uniq! end
Parse the command-line args into the params hash.
'
Parse the command - line args into the params hash . '
# end of options parsing # --param=val or --param # -abc # -a val # -a=val