@@ -674,6 +674,29 @@ def compsys(sdone, ldone) # :nodoc:
674
674
end
675
675
end
676
676
677
+ def pretty_print_contents ( q ) # :nodoc:
678
+ if @block
679
+ q . text ":" + @block . source_location . join ( ":" ) + ":"
680
+ first = false
681
+ else
682
+ first = true
683
+ end
684
+ [ @short , @long ] . each do |list |
685
+ list . each do |opt |
686
+ if first
687
+ q . text ":"
688
+ first = false
689
+ end
690
+ q . breakable
691
+ q . text opt
692
+ end
693
+ end
694
+ end
695
+
696
+ def pretty_print ( q ) # :nodoc:
697
+ q . object_group ( self ) { pretty_print_contents ( q ) }
698
+ end
699
+
677
700
#
678
701
# Switch that takes no arguments.
679
702
#
@@ -693,6 +716,10 @@ def self.incompatible_argument_styles(*)
693
716
def self . pattern
694
717
Object
695
718
end
719
+
720
+ def pretty_head # :nodoc:
721
+ "NoArgument"
722
+ end
696
723
end
697
724
698
725
#
@@ -710,6 +737,10 @@ def parse(arg, argv)
710
737
end
711
738
conv_arg ( *parse_arg ( arg , &method ( :raise ) ) )
712
739
end
740
+
741
+ def pretty_head # :nodoc:
742
+ "Required"
743
+ end
713
744
end
714
745
715
746
#
@@ -727,6 +758,10 @@ def parse(arg, argv, &error)
727
758
conv_arg ( arg )
728
759
end
729
760
end
761
+
762
+ def pretty_head # :nodoc:
763
+ "Optional"
764
+ end
730
765
end
731
766
732
767
#
@@ -750,6 +785,10 @@ def parse(arg, argv, &error)
750
785
end
751
786
val
752
787
end
788
+
789
+ def pretty_head # :nodoc:
790
+ "Placed"
791
+ end
753
792
end
754
793
end
755
794
@@ -781,6 +820,17 @@ def initialize
781
820
@list = [ ]
782
821
end
783
822
823
+ def pretty_print ( q ) # :nodoc:
824
+ q . group ( 1 , "(" , ")" ) do
825
+ @list . each do |sw |
826
+ next unless Switch === sw
827
+ q . group ( 1 , "(" + sw . pretty_head , ")" ) do
828
+ sw . pretty_print_contents ( q )
829
+ end
830
+ end
831
+ end
832
+ end
833
+
784
834
#
785
835
# See OptionParser.accept.
786
836
#
@@ -1293,6 +1343,29 @@ def summarize(to = [], width = @summary_width, max = width - 1, indent = @summar
1293
1343
def help ; summarize ( "#{ banner } " . sub ( /\n ?\z / , "\n " ) ) end
1294
1344
alias to_s help
1295
1345
1346
+ def pretty_print ( q ) # :nodoc:
1347
+ q . object_group ( self ) do
1348
+ first = true
1349
+ if @stack . size > 2
1350
+ @stack . each_with_index do |s , i |
1351
+ next if i < 2
1352
+ next if s . list . empty?
1353
+ if first
1354
+ first = false
1355
+ q . text ":"
1356
+ end
1357
+ q . breakable
1358
+ s . pretty_print ( q )
1359
+ end
1360
+ end
1361
+ end
1362
+ end
1363
+
1364
+ def inspect # :nodoc:
1365
+ require 'pp'
1366
+ pretty_print_inspect
1367
+ end
1368
+
1296
1369
#
1297
1370
# Returns option summary list.
1298
1371
#
0 commit comments