Project

General

Profile

Feature #8460 ยป 0001-optparse-add-keep_unknown-option.patch

felipec (Felipe Contreras), 05/29/2013 08:39 PM

View differences:

lib/optparse.rb
881 881
    @summary_width = width
882 882
    @summary_indent = indent
883 883
    @default_argv = ARGV
884
    @keep_unknown = false
884 885
    add_officious
885 886
    yield self if block_given?
886 887
  end
......
954 955
  # Strings to be parsed in default.
955 956
  attr_accessor :default_argv
956 957

  
958
  attr_writer :keep_unknown
959

  
957 960
  #
958 961
  # Heading banner preceding summary.
959 962
  #
......
1356 1359
          opt, rest = $1, $2
1357 1360
          begin
1358 1361
            sw, = complete(:long, opt, true)
1362
          rescue InvalidOption
1363
            if @keep_unknown
1364
              nonopt.call(arg)
1365
              next
1366
            end
1367
            raise $!
1359 1368
          rescue ParseError
1360 1369
            raise $!.set_option(arg, true)
1361 1370
          end
......
1381 1390
              rescue InvalidOption
1382 1391
                # if no short options match, try completion with long
1383 1392
                # options.
1384
                sw, = complete(:long, opt)
1393
                begin
1394
                  sw, = complete(:long, opt)
1395
                rescue InvalidOption
1396
                  if @keep_unknown
1397
                    nonopt.call(arg)
1398
                    next
1399
                  end
1400
                  raise $!
1401
                end
1385 1402
                eq ||= !rest
1386 1403
              end
1387 1404
            end
1388
-