diff options
author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2022-04-28 17:15:43 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2022-04-28 19:08:49 +0900 |
commit | 1056489ea3e1c3f201936666b2725bfc142bb0f2 (patch) | |
tree | cc993148b660f7cc2d92823ccfafcf10d3009c0a /lib/rubygems/optparse/lib | |
parent | cd2410f9d8c99fd0fbb232eb5f195188fbfc122f (diff) |
Merge https://github.com/rubygems/rubygems/commit/3f7d0352e84b29d4a2d4cd93b31e5ebdb5f79cc6
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5669
Diffstat (limited to 'lib/rubygems/optparse/lib')
-rw-r--r-- | lib/rubygems/optparse/lib/optparse.rb | 77 | ||||
-rw-r--r-- | lib/rubygems/optparse/lib/optparse/ac.rb | 2 | ||||
-rw-r--r-- | lib/rubygems/optparse/lib/optparse/date.rb | 2 | ||||
-rw-r--r-- | lib/rubygems/optparse/lib/optparse/kwargs.rb | 2 | ||||
-rw-r--r-- | lib/rubygems/optparse/lib/optparse/shellwords.rb | 2 | ||||
-rw-r--r-- | lib/rubygems/optparse/lib/optparse/time.rb | 2 | ||||
-rw-r--r-- | lib/rubygems/optparse/lib/optparse/uri.rb | 2 |
7 files changed, 81 insertions, 8 deletions
diff --git a/lib/rubygems/optparse/lib/optparse.rb b/lib/rubygems/optparse/lib/optparse.rb index e4b1c61f79..98865612ba 100644 --- a/lib/rubygems/optparse/lib/optparse.rb +++ b/lib/rubygems/optparse/lib/optparse.rb @@ -50,7 +50,7 @@ # # === New to \Gem::OptionParser? # -# See the {Tutorial}[./doc/optparse/tutorial_rdoc.html]. +# See the {Tutorial}[optparse/tutorial.rdoc]. # # === Introduction # @@ -420,7 +420,7 @@ # === Further documentation # # The above examples, along with the accompanying -# {Tutorial}[./doc/optparse/tutorial_rdoc.html], +# {Tutorial}[optparse/tutorial.rdoc], # should be enough to learn how to use this class. # If you have any questions, file a ticket at http://bugs.ruby-lang.org. # @@ -674,6 +674,29 @@ class Gem::OptionParser end end + def pretty_print_contents(q) # :nodoc: + if @block + q.text ":" + @block.source_location.join(":") + ":" + first = false + else + first = true + end + [@short, @long].each do |list| + list.each do |opt| + if first + q.text ":" + first = false + end + q.breakable + q.text opt + end + end + end + + def pretty_print(q) # :nodoc: + q.object_group(self) {pretty_print_contents(q)} + end + # # Switch that takes no arguments. # @@ -693,6 +716,10 @@ class Gem::OptionParser def self.pattern Object end + + def pretty_head # :nodoc: + "NoArgument" + end end # @@ -710,6 +737,10 @@ class Gem::OptionParser end conv_arg(*parse_arg(arg, &method(:raise))) end + + def pretty_head # :nodoc: + "Required" + end end # @@ -727,6 +758,10 @@ class Gem::OptionParser conv_arg(arg) end end + + def pretty_head # :nodoc: + "Optional" + end end # @@ -750,6 +785,10 @@ class Gem::OptionParser end val end + + def pretty_head # :nodoc: + "Placed" + end end end @@ -781,6 +820,17 @@ class Gem::OptionParser @list = [] end + def pretty_print(q) # :nodoc: + q.group(1, "(", ")") do + @list.each do |sw| + next unless Switch === sw + q.group(1, "(" + sw.pretty_head, ")") do + sw.pretty_print_contents(q) + end + end + end + end + # # See Gem::OptionParser.accept. # @@ -1293,6 +1343,29 @@ XXX def help; summarize("#{banner}".sub(/\n?\z/, "\n")) end alias to_s help + def pretty_print(q) # :nodoc: + q.object_group(self) do + first = true + if @stack.size > 2 + @stack.each_with_index do |s, i| + next if i < 2 + next if s.list.empty? + if first + first = false + q.text ":" + end + q.breakable + s.pretty_print(q) + end + end + end + end + + def inspect # :nodoc: + require 'pp' + pretty_print_inspect + end + # # Returns option summary list. # diff --git a/lib/rubygems/optparse/lib/optparse/ac.rb b/lib/rubygems/optparse/lib/optparse/ac.rb index ff2f4c2dc3..e84d01bf91 100644 --- a/lib/rubygems/optparse/lib/optparse/ac.rb +++ b/lib/rubygems/optparse/lib/optparse/ac.rb @@ -1,5 +1,5 @@ # frozen_string_literal: false -require 'rubygems/optparse/lib/optparse' +require_relative '../optparse' class Gem::OptionParser::AC < Gem::OptionParser private diff --git a/lib/rubygems/optparse/lib/optparse/date.rb b/lib/rubygems/optparse/lib/optparse/date.rb index 11131e92c2..d9a9f4f48a 100644 --- a/lib/rubygems/optparse/lib/optparse/date.rb +++ b/lib/rubygems/optparse/lib/optparse/date.rb @@ -1,5 +1,5 @@ # frozen_string_literal: false -require 'rubygems/optparse/lib/optparse' +require_relative '../optparse' require 'date' Gem::OptionParser.accept(DateTime) do |s,| diff --git a/lib/rubygems/optparse/lib/optparse/kwargs.rb b/lib/rubygems/optparse/lib/optparse/kwargs.rb index 9290344c39..6987a5ed62 100644 --- a/lib/rubygems/optparse/lib/optparse/kwargs.rb +++ b/lib/rubygems/optparse/lib/optparse/kwargs.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'rubygems/optparse/lib/optparse' +require_relative '../optparse' class Gem::OptionParser # :call-seq: diff --git a/lib/rubygems/optparse/lib/optparse/shellwords.rb b/lib/rubygems/optparse/lib/optparse/shellwords.rb index 60dd91990c..d47ad60255 100644 --- a/lib/rubygems/optparse/lib/optparse/shellwords.rb +++ b/lib/rubygems/optparse/lib/optparse/shellwords.rb @@ -2,6 +2,6 @@ # -*- ruby -*- require 'shellwords' -require 'rubygems/optparse/lib/optparse' +require_relative '../optparse' Gem::OptionParser.accept(Shellwords) {|s,| Shellwords.shellwords(s)} diff --git a/lib/rubygems/optparse/lib/optparse/time.rb b/lib/rubygems/optparse/lib/optparse/time.rb index cb19f6e998..c59e1e4ced 100644 --- a/lib/rubygems/optparse/lib/optparse/time.rb +++ b/lib/rubygems/optparse/lib/optparse/time.rb @@ -1,5 +1,5 @@ # frozen_string_literal: false -require 'rubygems/optparse/lib/optparse' +require_relative '../optparse' require 'time' Gem::OptionParser.accept(Time) do |s,| diff --git a/lib/rubygems/optparse/lib/optparse/uri.rb b/lib/rubygems/optparse/lib/optparse/uri.rb index 088f309992..664d7f2af4 100644 --- a/lib/rubygems/optparse/lib/optparse/uri.rb +++ b/lib/rubygems/optparse/lib/optparse/uri.rb @@ -1,7 +1,7 @@ # frozen_string_literal: false # -*- ruby -*- -require 'rubygems/optparse/lib/optparse' +require_relative '../optparse' require 'uri' Gem::OptionParser.accept(URI) {|s,| URI.parse(s) if s} |