summaryrefslogtreecommitdiff
path: root/lib/optparse.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-10-30 00:36:19 +0900
committergit <svn-admin@ruby-lang.org>2022-11-28 14:24:06 +0000
commit0bfb185654b13237b874dc00d5719e695416b711 (patch)
treee5e0e9303e961d7642a5b939c6f405e62d24893b /lib/optparse.rb
parentdcf94e719c6fca527f219a4c9fa79e13fd3d4484 (diff)
[ruby/optparse] Add `raise_unknown` flag
(https://github.com/ruby/optparse/pull/38) https://github.com/ruby/optparse/commit/12529653cd
Diffstat (limited to 'lib/optparse.rb')
-rw-r--r--lib/optparse.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/optparse.rb b/lib/optparse.rb
index 7ddde82342..7cc7d10982 100644
--- a/lib/optparse.rb
+++ b/lib/optparse.rb
@@ -1148,6 +1148,7 @@ XXX
@summary_indent = indent
@default_argv = ARGV
@require_exact = false
+ @raise_unknown = true
add_officious
yield self if block_given?
end
@@ -1225,6 +1226,9 @@ XXX
# abbreviated long option as short option).
attr_accessor :require_exact
+ # Whether to raise at unknown option.
+ attr_accessor :raise_unknown
+
#
# Heading banner preceding summary.
#
@@ -1639,9 +1643,11 @@ XXX
begin
sw, = complete(:long, opt, true)
if require_exact && !sw.long.include?(arg)
+ throw :terminate, arg unless raise_unknown
raise InvalidOption, arg
end
rescue ParseError
+ throw :terminate, arg unless raise_unknown
raise $!.set_option(arg, true)
end
begin
@@ -1673,6 +1679,7 @@ XXX
end
end
rescue ParseError
+ throw :terminate, arg unless raise_unknown
raise $!.set_option(arg, true)
end
begin