@@ -1148,6 +1148,7 @@ def initialize(banner = nil, width = 32, indent = ' ' * 4)
1148
1148
@summary_indent = indent
1149
1149
@default_argv = ARGV
1150
1150
@require_exact = false
1151
+ @raise_unknown = true
1151
1152
add_officious
1152
1153
yield self if block_given?
1153
1154
end
@@ -1225,6 +1226,9 @@ def self.reject(*args, &blk) top.reject(*args, &blk) end
1225
1226
# abbreviated long option as short option).
1226
1227
attr_accessor :require_exact
1227
1228
1229
+ # Whether to raise at unknown option.
1230
+ attr_accessor :raise_unknown
1231
+
1228
1232
#
1229
1233
# Heading banner preceding summary.
1230
1234
#
@@ -1639,9 +1643,11 @@ def parse_in_order(argv = default_argv, setter = nil, &nonopt) # :nodoc:
1639
1643
begin
1640
1644
sw , = complete ( :long , opt , true )
1641
1645
if require_exact && !sw . long . include? ( arg )
1646
+ throw :terminate , arg unless raise_unknown
1642
1647
raise InvalidOption , arg
1643
1648
end
1644
1649
rescue ParseError
1650
+ throw :terminate , arg unless raise_unknown
1645
1651
raise $!. set_option ( arg , true )
1646
1652
end
1647
1653
begin
@@ -1673,6 +1679,7 @@ def parse_in_order(argv = default_argv, setter = nil, &nonopt) # :nodoc:
1673
1679
end
1674
1680
end
1675
1681
rescue ParseError
1682
+ throw :terminate , arg unless raise_unknown
1676
1683
raise $!. set_option ( arg , true )
1677
1684
end
1678
1685
begin
0 commit comments