optparse 0.2.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45145f867a14905754ed4e60fa3a217e5dd141afac7763be973a90aa488a4e1d
4
- data.tar.gz: 925392a4e752b2fd4dbd2a26b9446e580c4c2e375611659d705b7f685b149c9a
3
+ metadata.gz: 3726480fe0a25a9efd1cec645f993256cda45ac050411f046dfb6fa35117414a
4
+ data.tar.gz: ace5491689e1e277cd9b0a37b7ff070be46e46b6cb1b3b21f19c02d4d2d792a1
5
5
  SHA512:
6
- metadata.gz: 1cbaf965329a82b9ec5ba8af7f4f56e4e91b54f4dfc524d0a1aa3abe4a72f5f2bb64af95d2a1d504bb3dd4cb24243dcf8aa346fbd14caf9959045bb9edf2d73b
7
- data.tar.gz: 8e3c1ee8582ad9b524db35a864c0eafd4adcf4dd6475bb8c2faa6cad0aad1f3fe17617a681fb4319f632fa205a175be45f29920eeca9404a8b662f41565edb64
6
+ metadata.gz: af882a7ff3c55fc882fbbc1259d104a55dd15049b64b3022459e868c4a00ba989ac651b5f7c16a260a97c8f4992b07adc3b03ca23ad231adf46cae62be6ae8b6
7
+ data.tar.gz: 42d6f1e638d8fdbb43953e0ecda55a00b9460d375a1cb8175bd14dcdbbc2fd94996fae031b0b7f31881d73dc6fa2815c75d146fc2fedc2ea9551797118be22e5
data/ChangeLog CHANGED
@@ -1,264 +1,25 @@
1
1
  -*- coding: utf-8 -*-
2
2
 
3
- commit 1226b670e60d5ec8ad4c1a6b73040c9fdcf40fe2
3
+ commit 2a1e157ae134b07b8412182502755ec4eb3af499
4
4
  Author: Hiroshi SHIBATA <hsbt@ruby-lang.org>
5
- AuthorDate: 2021-10-21 20:38:56 +0900
5
+ AuthorDate: 2022-12-22 17:47:34 +0900
6
6
  Commit: Hiroshi SHIBATA <hsbt@ruby-lang.org>
7
- CommitDate: 2021-10-21 20:38:56 +0900
7
+ CommitDate: 2022-12-22 17:47:34 +0900
8
8
 
9
- Bump up optparse version to 0.2.0
9
+ Bump version to 0.3.1
10
10
 
11
- commit 0281b949c6cf86806a260ca6b39267d9b202fbf8
11
+ commit 766f567405a362d0e018d8411df15ce8d70573a6
12
12
  Author: Nobuyoshi Nakada <nobu@ruby-lang.org>
13
- AuthorDate: 2021-09-29 11:45:11 +0900
14
- Commit: Nobuyoshi Nakada <nobu@ruby-lang.org>
15
- CommitDate: 2021-09-29 11:45:11 +0900
16
-
17
- Add the argument from where synchronize tools
18
-
19
- commit a3d05c1be8efb552b64f3d1af84b8b8dea8e0afb
20
- Author: Nobuyoshi Nakada <nobu@ruby-lang.org>
21
- AuthorDate: 2021-09-29 11:34:44 +0900
22
- Commit: Nobuyoshi Nakada <nobu@ruby-lang.org>
23
- CommitDate: 2021-09-29 11:34:44 +0900
24
-
25
- Revived `rdoc` task
26
-
27
- commit 6a2fa9737f5dab99c73a99a24472f620fff228ea
28
- Author: Hiroshi SHIBATA <hsbt@ruby-lang.org>
29
- AuthorDate: 2021-09-11 13:21:00 +0900
30
- Commit: Hiroshi SHIBATA <hsbt@ruby-lang.org>
31
- CommitDate: 2021-09-11 13:21:00 +0900
32
-
33
- Bump up the latest version of CoreAssertions
34
-
35
- commit bf03038d953902569c11448717ab584c65e35a89
36
- Author: Burdette Lamar <BurdetteLamar@Yahoo.com>
37
- AuthorDate: 2021-04-22 14:22:11 -0500
38
- Commit: Burdette Lamar <BurdetteLamar@Yahoo.com>
39
- CommitDate: 2021-04-22 14:22:11 -0500
40
-
41
- Fix link in included file
42
-
43
- commit 47417f1b4cb5d819aa54f305a4009f45d7a112c1
44
- Author: Olle Jonsson <olle.jonsson@gmail.com>
45
- AuthorDate: 2021-04-23 13:04:25 +0200
46
- Commit: GitHub <noreply@github.com>
47
- CommitDate: 2021-04-23 06:04:25 -0500
48
-
49
- Remove an errant { character (#26)
50
-
51
- commit 40d51ccbad75ab5194ce5a3574b49fda41745849
52
- Author: Burdette Lamar <BurdetteLamar@Yahoo.com>
53
- AuthorDate: 2021-04-22 08:48:23 -0500
54
- Commit: GitHub <noreply@github.com>
55
- CommitDate: 2021-04-22 08:48:23 -0500
56
-
57
- More on tutorial (#24)
58
-
59
- - Adds section "Parsing" to tutorial.rdoc.
60
- - Removes section "Terminators" from option_params.rdoc. (Terminator '--' is not an option parameter.)
61
-
62
- commit 7f3195b9dbc3a984a5d3e928a9d70686484411c0
63
- Author: Burdette Lamar <BurdetteLamar@Yahoo.com>
64
- AuthorDate: 2021-04-22 07:27:06 -0500
65
- Commit: GitHub <noreply@github.com>
66
- CommitDate: 2021-04-22 07:27:06 -0500
67
-
68
- More on tutorial (#23)
69
-
70
- - Removed a largish block of repeated text.
71
- - Added sections "Top List and Base List" and "Methods for Defining Options" (on, define, etc.).
72
- - Linked from class OptionParser doc to the tutorial.
73
-
74
- commit 7ef3d89e7859552daa057b6d5f42ffe3e562ae34
75
- Author: Nobuyoshi Nakada <nobu@ruby-lang.org>
76
- AuthorDate: 2021-04-16 12:57:55 +0900
77
- Commit: Nobuyoshi Nakada <nobu@ruby-lang.org>
78
- CommitDate: 2021-04-16 12:57:55 +0900
79
-
80
- Removed a duplicate section
81
-
82
- commit 9c5b3f244b723e0231ef07c56c59dabf56a9dd3f
83
- Author: Burdette Lamar <BurdetteLamar@Yahoo.com>
84
- AuthorDate: 2021-04-15 09:32:02 -0500
85
- Commit: GitHub <noreply@github.com>
86
- CommitDate: 2021-04-15 09:32:02 -0500
87
-
88
- More on tutorial (#22)
89
-
90
- Adds argument abbreviation in option_params.rdoc.
91
- Adds entire Argument Values section to tutorial.rdoc.
92
-
93
- commit d07cb96a9616ae7489e41db7bb85e43a9b664831
94
- Author: Burdette Lamar <BurdetteLamar@Yahoo.com>
95
- AuthorDate: 2021-04-12 20:33:19 -0500
96
- Commit: GitHub <noreply@github.com>
97
- CommitDate: 2021-04-13 10:33:19 +0900
98
-
99
- Rdoc for help (#21)
100
-
101
- commit 385dd4322de67a989e5d271ed7ddb96b2375956f
102
- Author: Burdette Lamar <BurdetteLamar@Yahoo.com>
103
- AuthorDate: 2021-04-11 23:43:02 -0500
104
- Commit: GitHub <noreply@github.com>
105
- CommitDate: 2021-04-12 06:43:02 +0200
106
-
107
- Tutorial: explain custom argument converters (#19)
108
-
109
- commit f23d750d14936c0e3663f65ad1b97be82d232dae
110
- Author: Nobuyoshi Nakada <nobu@ruby-lang.org>
111
- AuthorDate: 2021-04-12 02:02:11 +0900
112
- Commit: Nobuyoshi Nakada <nobu@ruby-lang.org>
113
- CommitDate: 2021-04-12 02:02:11 +0900
114
-
115
- nodoc private methods
116
-
117
- commit 7e65ef3cfa3a38aaac3a61e1a82307427f1d27c1
118
- Author: Nobuyoshi Nakada <nobu@ruby-lang.org>
119
- AuthorDate: 2021-04-12 00:38:40 +0900
120
- Commit: Nobuyoshi Nakada <nobu@ruby-lang.org>
121
- CommitDate: 2021-04-12 00:38:40 +0900
122
-
123
- Fixed mismatched <tt> tag
124
-
125
- commit cccb28e0debbf0f96162291766d3ccafc2c558a3
126
- Author: Nobuyoshi Nakada <nobu@ruby-lang.org>
127
- AuthorDate: 2021-04-11 09:03:07 +0900
128
- Commit: Nobuyoshi Nakada <nobu@ruby-lang.org>
129
- CommitDate: 2021-04-11 09:03:07 +0900
130
-
131
- Moved rdoc files to doc/optparse
132
-
133
- commit 8be031b5392cb440f3df23304805c8c814265c59
134
- Author: Nobuyoshi Nakada <nobu@ruby-lang.org>
135
- AuthorDate: 2021-04-11 08:49:30 +0900
136
- Commit: Nobuyoshi Nakada <nobu@ruby-lang.org>
137
- CommitDate: 2021-04-11 08:51:44 +0900
138
-
139
- Fix relative paths
140
-
141
- commit 01c24ca4f606a455b8d135a48e11a0371ef6d7c0
142
- Author: Nobuyoshi Nakada <nobu@ruby-lang.org>
143
- AuthorDate: 2021-04-11 08:24:03 +0900
144
- Commit: Nobuyoshi Nakada <nobu@ruby-lang.org>
145
- CommitDate: 2021-04-11 08:24:03 +0900
146
-
147
- Added `rdoc` task
148
-
149
- commit 4ff48f24c9b44740dd6c63bc5005db8959c21f80
150
- Author: Nobuyoshi Nakada <nobu@ruby-lang.org>
151
- AuthorDate: 2021-04-09 23:20:03 +0900
152
- Commit: Nobuyoshi Nakada <nobu@ruby-lang.org>
153
- CommitDate: 2021-04-11 08:10:41 +0900
154
-
155
- No document in rakelib
156
-
157
- commit 39d39676c45083953a082c4f6e2e8a7315b7066d
158
- Author: Burdette Lamar <BurdetteLamar@Yahoo.com>
159
- AuthorDate: 2021-04-10 16:30:19 -0500
160
- Commit: GitHub <noreply@github.com>
161
- CommitDate: 2021-04-10 16:30:19 -0500
162
-
163
- More on tutorial (#16)
164
-
165
- - Added example in "Argument Converters"; it doesn't seem right for a tutorial to have no example in one of its topics (and instead just linking elsewhere).
166
- - Added section "Command-Line Abbreviations."
167
- - Added section "Keyword Argument into," showing how to:
168
- - Collect options.
169
- - Check for missing options.
170
- - Provide option defaults.
171
-
172
- commit c91ed8d33db7355cf0a5a8323f3f6aad57e18b38
173
- Author: Burdette Lamar <BurdetteLamar@Yahoo.com>
174
- AuthorDate: 2021-04-10 10:05:44 -0500
175
- Commit: GitHub <noreply@github.com>
176
- CommitDate: 2021-04-10 10:05:44 -0500
177
-
178
- Rdoc (#15)
179
-
180
- * Resolve shared mixed_names.rb
181
-
182
- * Add long option with negation
183
-
184
- * Show --help for all examples
185
-
186
- * Table of contents for tutorial
187
-
188
- * Move argument converters to separate rdoc
189
-
190
- * Add references to argument_converters.rdoc
191
-
192
- * Tune up argument converters
193
-
194
- * Change explicit links to auto-links
195
-
196
- commit 9a2352c1c9c3445d1618da577f19137243a2a748
197
- Author: Burdette Lamar <BurdetteLamar@Yahoo.com>
198
- AuthorDate: 2021-04-09 08:21:34 -0500
13
+ AuthorDate: 2022-12-21 14:07:54 +0900
199
14
  Commit: GitHub <noreply@github.com>
200
- CommitDate: 2021-04-09 08:21:34 -0500
15
+ CommitDate: 2022-12-21 14:07:54 +0900
201
16
 
202
- Reorganize Ruby example files for sharing (#14)
17
+ The encoding argument of `Regexp.new` has been ignored since 1.9
203
18
 
204
- commit f3ca83caff20f6daf07a70a3f3f41a6666790b6c
205
- Author: Olle Jonsson <olle.jonsson@gmail.com>
206
- AuthorDate: 2021-04-08 05:33:56 +0200
207
- Commit: GitHub <noreply@github.com>
208
- CommitDate: 2021-04-08 12:33:56 +0900
209
-
210
- gemspec: Explicit files list (#10)
211
-
212
- This avoid shelling out, and includes a narrower list of files.
213
-
214
- Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
215
-
216
- commit d55d9284c3a02a794d63a842764591d4ff079241
217
- Author: BurdetteLamar <burdettelamar@yahoo.com>
218
- AuthorDate: 2021-04-07 11:58:46 -0500
219
- Commit: Nobuyoshi Nakada <nobu@ruby-lang.org>
220
- CommitDate: 2021-04-08 10:40:59 +0900
221
-
222
- Make use of option_params.rdoc
223
-
224
- commit 5618eeb49ee2a316cd5d91a515dbb2734f553027
225
- Author: Burdette Lamar <BurdetteLamar@Yahoo.com>
226
- AuthorDate: 2021-04-07 09:01:52 -0500
227
- Commit: GitHub <noreply@github.com>
228
- CommitDate: 2021-04-07 16:01:52 +0200
229
-
230
- Enhanced doc for option parameters (#11)
231
-
232
- commit 84dfd92d2a7fb75bb40fbb8414bd8b90b7ccbac6
233
- Author: Burdette Lamar <BurdetteLamar@Yahoo.com>
234
- AuthorDate: 2021-04-06 13:55:21 -0500
235
- Commit: GitHub <noreply@github.com>
236
- CommitDate: 2021-04-06 13:55:21 -0500
237
-
238
- More on tutorial (#9)
239
-
240
- * More on tutorial
241
-
242
- * More on tutorial
243
-
244
- * More on tutorial
245
-
246
- * More on tutorial: clearer example output
247
-
248
- commit d14bf830078c2b2c8c8bcbe60aa2a2ebb40e0b6c
249
- Author: Olle Jonsson <olle.jonsson@gmail.com>
250
- AuthorDate: 2021-04-06 10:01:37 +0200
251
- Commit: GitHub <noreply@github.com>
252
- CommitDate: 2021-04-06 10:01:37 +0200
253
-
254
- gemspec: Explicitly list 0 executables
255
-
256
- This gem exposes no executable files.
257
-
258
- commit f209276f79d84578d4e40004ce7768194aae00cc
259
- Author: BurdetteLamar <burdettelamar@yahoo.com>
260
- AuthorDate: 2021-03-29 14:03:04 -0500
261
- Commit: Nobuyoshi Nakada <nobu@ruby-lang.org>
262
- CommitDate: 2021-03-30 12:00:31 +0900
19
+ commit 97a198673408d98686a4ec9c3457eef13088c981
20
+ Author: Junichi Sato <22004610+sato11@users.noreply.github.com>
21
+ AuthorDate: 2022-12-07 15:02:23 +0900
22
+ Commit: Hiroshi SHIBATA <hsbt@ruby-lang.org>
23
+ CommitDate: 2022-12-08 12:11:51 +0900
263
24
 
264
- Beginnings of tutorial
25
+ Use GITHUB_OUTPUT instead of deprecated set-output
@@ -1,7 +1,7 @@
1
1
  Creates an option from the given parameters +params+.
2
- See {Parameters for New Options}[./doc/optparse/option_params_rdoc.html].
2
+ See {Parameters for New Options}[optparse/option_params.rdoc].
3
3
 
4
4
  The block, if given, is the handler for the created option.
5
5
  When the option is encountered during command-line parsing,
6
6
  the block is called with the argument given for the option, if any.
7
- See {Option Handlers}[./option_params_rdoc.html#label-Option+Handlers].
7
+ See {Option Handlers}[optparse/option_params.rdoc#label-Option+Handlers].
@@ -410,7 +410,7 @@ from the default \String to an instance of another class.
410
410
  There are a number of built-in converters.
411
411
  You can also define custom converters.
412
412
 
413
- See {Argument Converters}[./argument_converters_rdoc.html].
413
+ See {Argument Converters}[./argument_converters.rdoc].
414
414
 
415
415
  === Descriptions
416
416
 
@@ -418,7 +418,7 @@ A description parameter is any string parameter
418
418
  that is not recognized as an
419
419
  {option name}[#label-Option+Names] or a
420
420
  {terminator}[#label-Terminators];
421
- in other words, it does not begin with a hypnen.
421
+ in other words, it does not begin with a hyphen.
422
422
 
423
423
  You may give any number of description parameters;
424
424
  each becomes a line in the text generated by option <tt>--help</tt>.
@@ -453,7 +453,7 @@ when the option is encountered. The handler may be:
453
453
 
454
454
  ==== Handler Blocks
455
455
 
456
- An option hadler may be a block.
456
+ An option handler may be a block.
457
457
 
458
458
  File +block.rb+ defines an option that has a handler block.
459
459
 
@@ -541,7 +541,7 @@ Executions:
541
541
  [#<Date: 2001-02-03 ((2451944j,0s,0n),+0s,2299161j)>, Date]
542
542
 
543
543
  You can also define custom converters.
544
- See {Argument Converters}[./argument_converters_rdoc.html]
544
+ See {Argument Converters}[./argument_converters.rdoc]
545
545
  for both built-in and custom converters.
546
546
 
547
547
  === Help
@@ -657,7 +657,7 @@ Though you may never need to call it directly,
657
657
  here's the core method for defining an option:
658
658
 
659
659
  - \Method \OptionParser#make_switch accepts an array of parameters and a block.
660
- See {Parameters for New Options}[./option_params_rdoc.html].
660
+ See {Parameters for New Options}[optparse/option_params.rdoc].
661
661
  This method is unlike others here in that it:
662
662
  - Accepts an <em>array of parameters</em>;
663
663
  others accept a <em>sequence of parameter arguments</em>.
data/lib/optparse/ac.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: false
2
- require 'optparse'
2
+ require_relative '../optparse'
3
3
 
4
4
  class OptionParser::AC < OptionParser
5
5
  private
data/lib/optparse/date.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: false
2
- require 'optparse'
2
+ require_relative '../optparse'
3
3
  require 'date'
4
4
 
5
5
  OptionParser.accept(DateTime) do |s,|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- require 'optparse'
2
+ require_relative '../optparse'
3
3
 
4
4
  class OptionParser
5
5
  # :call-seq:
@@ -2,6 +2,6 @@
2
2
  # -*- ruby -*-
3
3
 
4
4
  require 'shellwords'
5
- require 'optparse'
5
+ require_relative '../optparse'
6
6
 
7
7
  OptionParser.accept(Shellwords) {|s,| Shellwords.shellwords(s)}
data/lib/optparse/time.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: false
2
- require 'optparse'
2
+ require_relative '../optparse'
3
3
  require 'time'
4
4
 
5
5
  OptionParser.accept(Time) do |s,|
data/lib/optparse/uri.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: false
2
2
  # -*- ruby -*-
3
3
 
4
- require 'optparse'
4
+ require_relative '../optparse'
5
5
  require 'uri'
6
6
 
7
7
  OptionParser.accept(URI) {|s,| URI.parse(s) if s}
data/lib/optparse.rb CHANGED
@@ -50,7 +50,7 @@
50
50
  #
51
51
  # === New to \OptionParser?
52
52
  #
53
- # See the {Tutorial}[./doc/optparse/tutorial_rdoc.html].
53
+ # See the {Tutorial}[optparse/tutorial.rdoc].
54
54
  #
55
55
  # === Introduction
56
56
  #
@@ -420,12 +420,12 @@
420
420
  # === Further documentation
421
421
  #
422
422
  # The above examples, along with the accompanying
423
- # {Tutorial}[./doc/optparse/tutorial_rdoc.html],
423
+ # {Tutorial}[optparse/tutorial.rdoc],
424
424
  # should be enough to learn how to use this class.
425
425
  # If you have any questions, file a ticket at http://bugs.ruby-lang.org.
426
426
  #
427
427
  class OptionParser
428
- OptionParser::Version = "0.2.0"
428
+ OptionParser::Version = "0.3.1"
429
429
 
430
430
  # :stopdoc:
431
431
  NoArgument = [NO_ARGUMENT = :NONE, nil].freeze
@@ -674,6 +674,29 @@ class OptionParser
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 @@ class OptionParser
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 @@ class OptionParser
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,18 +758,22 @@ class OptionParser
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
  #
733
- # Switch that takes an argument, which does not begin with '-'.
768
+ # Switch that takes an argument, which does not begin with '-' or is '-'.
734
769
  #
735
770
  class PlacedArgument < self
736
771
 
737
772
  #
738
- # Returns nil if argument is not present or begins with '-'.
773
+ # Returns nil if argument is not present or begins with '-' and is not '-'.
739
774
  #
740
775
  def parse(arg, argv, &error)
741
- if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
776
+ if !(val = arg) and (argv.empty? or /\A-./ =~ (val = argv[0]))
742
777
  return nil, block, nil
743
778
  end
744
779
  opt = (val = parse_arg(val, &error))[1]
@@ -750,6 +785,10 @@ class OptionParser
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 @@ class OptionParser
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
  #
@@ -1098,6 +1148,7 @@ XXX
1098
1148
  @summary_indent = indent
1099
1149
  @default_argv = ARGV
1100
1150
  @require_exact = false
1151
+ @raise_unknown = true
1101
1152
  add_officious
1102
1153
  yield self if block_given?
1103
1154
  end
@@ -1175,6 +1226,9 @@ XXX
1175
1226
  # abbreviated long option as short option).
1176
1227
  attr_accessor :require_exact
1177
1228
 
1229
+ # Whether to raise at unknown option.
1230
+ attr_accessor :raise_unknown
1231
+
1178
1232
  #
1179
1233
  # Heading banner preceding summary.
1180
1234
  #
@@ -1293,6 +1347,29 @@ XXX
1293
1347
  def help; summarize("#{banner}".sub(/\n?\z/, "\n")) end
1294
1348
  alias to_s help
1295
1349
 
1350
+ def pretty_print(q) # :nodoc:
1351
+ q.object_group(self) do
1352
+ first = true
1353
+ if @stack.size > 2
1354
+ @stack.each_with_index do |s, i|
1355
+ next if i < 2
1356
+ next if s.list.empty?
1357
+ if first
1358
+ first = false
1359
+ q.text ":"
1360
+ end
1361
+ q.breakable
1362
+ s.pretty_print(q)
1363
+ end
1364
+ end
1365
+ end
1366
+ end
1367
+
1368
+ def inspect # :nodoc:
1369
+ require 'pp'
1370
+ pretty_print_inspect
1371
+ end
1372
+
1296
1373
  #
1297
1374
  # Returns option summary list.
1298
1375
  #
@@ -1429,7 +1506,7 @@ XXX
1429
1506
  style = notwice(default_style.guess(arg = o), style, 'style')
1430
1507
  default_pattern, conv = search(:atype, Object) unless default_pattern
1431
1508
  else
1432
- desc.push(o)
1509
+ desc.push(o) if o && !o.empty?
1433
1510
  end
1434
1511
  end
1435
1512
 
@@ -1566,9 +1643,11 @@ XXX
1566
1643
  begin
1567
1644
  sw, = complete(:long, opt, true)
1568
1645
  if require_exact && !sw.long.include?(arg)
1646
+ throw :terminate, arg unless raise_unknown
1569
1647
  raise InvalidOption, arg
1570
1648
  end
1571
1649
  rescue ParseError
1650
+ throw :terminate, arg unless raise_unknown
1572
1651
  raise $!.set_option(arg, true)
1573
1652
  end
1574
1653
  begin
@@ -1600,6 +1679,7 @@ XXX
1600
1679
  end
1601
1680
  end
1602
1681
  rescue ParseError
1682
+ throw :terminate, arg unless raise_unknown
1603
1683
  raise $!.set_option(arg, true)
1604
1684
  end
1605
1685
  begin
@@ -1830,10 +1910,13 @@ XXX
1830
1910
  # directory ~/.options, then the basename with '.options' suffix
1831
1911
  # under XDG and Haiku standard places.
1832
1912
  #
1833
- def load(filename = nil)
1913
+ # The optional +into+ keyword argument works exactly like that accepted in
1914
+ # method #parse.
1915
+ #
1916
+ def load(filename = nil, into: nil)
1834
1917
  unless filename
1835
1918
  basename = File.basename($0, '.*')
1836
- return true if load(File.expand_path(basename, '~/.options')) rescue nil
1919
+ return true if load(File.expand_path(basename, '~/.options'), into: into) rescue nil
1837
1920
  basename << ".options"
1838
1921
  return [
1839
1922
  # XDG
@@ -1845,11 +1928,11 @@ XXX
1845
1928
  '~/config/settings',
1846
1929
  ].any? {|dir|
1847
1930
  next if !dir or dir.empty?
1848
- load(File.expand_path(basename, dir)) rescue nil
1931
+ load(File.expand_path(basename, dir), into: into) rescue nil
1849
1932
  }
1850
1933
  end
1851
1934
  begin
1852
- parse(*IO.readlines(filename).each {|s| s.chomp!})
1935
+ parse(*File.readlines(filename, chomp: true), into: into)
1853
1936
  true
1854
1937
  rescue Errno::ENOENT, Errno::ENOTDIR
1855
1938
  false
@@ -2001,10 +2084,23 @@ XXX
2001
2084
  f |= Regexp::IGNORECASE if /i/ =~ o
2002
2085
  f |= Regexp::MULTILINE if /m/ =~ o
2003
2086
  f |= Regexp::EXTENDED if /x/ =~ o
2004
- k = o.delete("imx")
2005
- k = nil if k.empty?
2087
+ case o = o.delete("imx")
2088
+ when ""
2089
+ when "u"
2090
+ s = s.encode(Encoding::UTF_8)
2091
+ when "e"
2092
+ s = s.encode(Encoding::EUC_JP)
2093
+ when "s"
2094
+ s = s.encode(Encoding::SJIS)
2095
+ when "n"
2096
+ f |= Regexp::NOENCODING
2097
+ else
2098
+ raise OptionParser::InvalidArgument, "unknown regexp option - #{o}"
2099
+ end
2100
+ else
2101
+ s ||= all
2006
2102
  end
2007
- Regexp.new(s || all, f, k)
2103
+ Regexp.new(s, f)
2008
2104
  end
2009
2105
 
2010
2106
  #
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optparse
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nobu Nakada
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-21 00:00:00.000000000 Z
11
+ date: 2022-12-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: OptionParser is a class for command-line option analysis.
14
14
  email:
@@ -98,7 +98,10 @@ metadata:
98
98
  homepage_uri: https://github.com/ruby/optparse
99
99
  source_code_uri: https://github.com/ruby/optparse
100
100
  post_install_message:
101
- rdoc_options: []
101
+ rdoc_options:
102
+ - "--main=README.md"
103
+ - "--op=rdoc"
104
+ - "--page-dir=doc"
102
105
  require_paths:
103
106
  - lib
104
107
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -112,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
115
  - !ruby/object:Gem::Version
113
116
  version: '0'
114
117
  requirements: []
115
- rubygems_version: 3.3.0.dev
118
+ rubygems_version: 3.4.0.dev
116
119
  signing_key:
117
120
  specification_version: 4
118
121
  summary: OptionParser is a class for command-line option analysis.