[ruby/optparse] Define inspect
and pretty_inspect
https://github.com/ruby/optparse/commit/a3f0ec21b1
This commit is contained in:
parent
4db75b6fe7
commit
de427c3ce0
@ -674,6 +674,29 @@ class OptionParser
|
|||||||
end
|
end
|
||||||
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.
|
# Switch that takes no arguments.
|
||||||
#
|
#
|
||||||
@ -693,6 +716,10 @@ class OptionParser
|
|||||||
def self.pattern
|
def self.pattern
|
||||||
Object
|
Object
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def pretty_head # :nodoc:
|
||||||
|
"NoArgument"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -710,6 +737,10 @@ class OptionParser
|
|||||||
end
|
end
|
||||||
conv_arg(*parse_arg(arg, &method(:raise)))
|
conv_arg(*parse_arg(arg, &method(:raise)))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def pretty_head # :nodoc:
|
||||||
|
"Required"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -727,6 +758,10 @@ class OptionParser
|
|||||||
conv_arg(arg)
|
conv_arg(arg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def pretty_head # :nodoc:
|
||||||
|
"Optional"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -750,6 +785,10 @@ class OptionParser
|
|||||||
end
|
end
|
||||||
val
|
val
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def pretty_head # :nodoc:
|
||||||
|
"Placed"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -781,6 +820,17 @@ class OptionParser
|
|||||||
@list = []
|
@list = []
|
||||||
end
|
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 OptionParser.accept.
|
# See OptionParser.accept.
|
||||||
#
|
#
|
||||||
@ -1293,6 +1343,29 @@ XXX
|
|||||||
def help; summarize("#{banner}".sub(/\n?\z/, "\n")) end
|
def help; summarize("#{banner}".sub(/\n?\z/, "\n")) end
|
||||||
alias to_s help
|
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.
|
# Returns option summary list.
|
||||||
#
|
#
|
||||||
|
Loading…
x
Reference in New Issue
Block a user