diff options
author | Jeremy Evans <[email protected]> | 2019-07-01 15:19:16 -0700 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2021-03-29 15:55:41 +0900 |
commit | eca8ffaa0b446db0a1cacc82a2e73155f6fd3fce (patch) | |
tree | b1b350e2320862b9f9d1054171eacbc4f43b1693 /lib | |
parent | d474b19b5bcae951817319b821e62e68364767ad (diff) |
[ruby/optparse] Add OptionParser#require_exact accessor
This allows you to disable allowing abbreviations of long options
and using short options for long options.
Implements Ruby Feature #11523
https://github.com/ruby/optparse/commit/dfefb2d2e2
Diffstat (limited to 'lib')
-rw-r--r-- | lib/optparse.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/optparse.rb b/lib/optparse.rb index bc0e821460..af12e4255a 100644 --- a/lib/optparse.rb +++ b/lib/optparse.rb @@ -1091,6 +1091,7 @@ XXX @summary_width = width @summary_indent = indent @default_argv = ARGV + @require_exact = false add_officious yield self if block_given? end @@ -1164,6 +1165,10 @@ XXX # Strings to be parsed in default. attr_accessor :default_argv + # Whether to require that options match exactly (disallows providing + # abbreviated long option as short option). + attr_accessor :require_exact + # # Heading banner preceding summary. # @@ -1583,6 +1588,9 @@ XXX opt.tr!('_', '-') begin sw, = complete(:long, opt, true) + if require_exact && !sw.long.include?(arg) + raise InvalidOption, arg + end rescue ParseError raise $!.set_option(arg, true) end @@ -1607,6 +1615,7 @@ XXX val = arg.delete_prefix('-') has_arg = true rescue InvalidOption + raise if require_exact # if no short options match, try completion with long # options. sw, = complete(:long, opt) |