rbs 1.2.0 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +5 -1
- data/.gitignore +2 -0
- data/CHANGELOG.md +53 -0
- data/README.md +1 -1
- data/Rakefile +9 -0
- data/Steepfile +1 -0
- data/core/array.rbs +1 -1
- data/core/basic_object.rbs +1 -1
- data/core/io.rbs +1 -1
- data/core/kernel.rbs +2 -2
- data/core/marshal.rbs +4 -3
- data/docs/rbs_by_example.md +328 -0
- data/docs/sigs.md +3 -1
- data/docs/stdlib.md +1 -1
- data/docs/syntax.md +0 -3
- data/lib/rbs/definition_builder.rb +2 -18
- data/lib/rbs/definition_builder/ancestor_builder.rb +9 -2
- data/lib/rbs/errors.rb +36 -0
- data/lib/rbs/parser.rb +913 -892
- data/lib/rbs/parser.y +10 -6
- data/lib/rbs/prototype/rb.rb +7 -3
- data/lib/rbs/prototype/runtime.rb +118 -42
- data/lib/rbs/version.rb +1 -1
- data/rbs.gemspec +1 -1
- data/sig/ancestor_builder.rbs +2 -0
- data/sig/errors.rbs +15 -0
- data/sig/namespace.rbs +1 -1
- data/sig/polyfill.rbs +0 -18
- data/stdlib/dbm/0/dbm.rbs +43 -30
- data/stdlib/mutex_m/0/mutex_m.rbs +1 -1
- data/stdlib/net-http/0/net-http.rbs +1846 -0
- data/stdlib/optparse/0/optparse.rbs +1214 -0
- data/stdlib/resolv/0/resolv.rbs +1504 -0
- data/stdlib/socket/0/addrinfo.rbs +469 -0
- data/stdlib/socket/0/basic_socket.rbs +503 -0
- data/stdlib/socket/0/ip_socket.rbs +72 -0
- data/stdlib/socket/0/socket.rbs +2687 -0
- data/stdlib/socket/0/tcp_server.rbs +177 -0
- data/stdlib/socket/0/tcp_socket.rbs +35 -0
- data/stdlib/socket/0/udp_socket.rbs +111 -0
- data/stdlib/socket/0/unix_server.rbs +154 -0
- data/stdlib/socket/0/unix_socket.rbs +132 -0
- data/stdlib/timeout/0/timeout.rbs +5 -0
- data/steep/Gemfile.lock +12 -12
- metadata +16 -12
- data/bin/annotate-with-rdoc +0 -153
- data/bin/console +0 -14
- data/bin/query-rdoc +0 -103
- data/bin/rbs-prof +0 -9
- data/bin/run_in_md.rb +0 -49
- data/bin/setup +0 -8
- data/bin/sort +0 -89
- data/bin/steep +0 -4
- data/bin/test_runner.rb +0 -29
@@ -0,0 +1,1214 @@
|
|
1
|
+
# ## OptionParser
|
2
|
+
#
|
3
|
+
# ### Introduction
|
4
|
+
#
|
5
|
+
# OptionParser is a class for command-line option analysis. It is much more
|
6
|
+
# advanced, yet also easier to use, than GetoptLong, and is a more Ruby-oriented
|
7
|
+
# solution.
|
8
|
+
#
|
9
|
+
# ### Features
|
10
|
+
#
|
11
|
+
# 1. The argument specification and the code to handle it are written in the
|
12
|
+
# same place.
|
13
|
+
# 2. It can output an option summary; you don't need to maintain this string
|
14
|
+
# separately.
|
15
|
+
# 3. Optional and mandatory arguments are specified very gracefully.
|
16
|
+
# 4. Arguments can be automatically converted to a specified class.
|
17
|
+
# 5. Arguments can be restricted to a certain set.
|
18
|
+
#
|
19
|
+
#
|
20
|
+
# All of these features are demonstrated in the examples below. See
|
21
|
+
# #make_switch for full documentation.
|
22
|
+
#
|
23
|
+
# ### Minimal example
|
24
|
+
#
|
25
|
+
# require 'optparse'
|
26
|
+
#
|
27
|
+
# options = {}
|
28
|
+
# OptionParser.new do |parser|
|
29
|
+
# parser.banner = "Usage: example.rb [options]"
|
30
|
+
#
|
31
|
+
# parser.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
32
|
+
# options[:verbose] = v
|
33
|
+
# end
|
34
|
+
# end.parse!
|
35
|
+
#
|
36
|
+
# p options
|
37
|
+
# p ARGV
|
38
|
+
#
|
39
|
+
# ### Generating Help
|
40
|
+
#
|
41
|
+
# OptionParser can be used to automatically generate help for the commands you
|
42
|
+
# write:
|
43
|
+
#
|
44
|
+
# require 'optparse'
|
45
|
+
#
|
46
|
+
# Options = Struct.new(:name)
|
47
|
+
#
|
48
|
+
# class Parser
|
49
|
+
# def self.parse(options)
|
50
|
+
# args = Options.new("world")
|
51
|
+
#
|
52
|
+
# opt_parser = OptionParser.new do |parser|
|
53
|
+
# parser.banner = "Usage: example.rb [options]"
|
54
|
+
#
|
55
|
+
# parser.on("-nNAME", "--name=NAME", "Name to say hello to") do |n|
|
56
|
+
# args.name = n
|
57
|
+
# end
|
58
|
+
#
|
59
|
+
# parser.on("-h", "--help", "Prints this help") do
|
60
|
+
# puts parser
|
61
|
+
# exit
|
62
|
+
# end
|
63
|
+
# end
|
64
|
+
#
|
65
|
+
# opt_parser.parse!(options)
|
66
|
+
# return args
|
67
|
+
# end
|
68
|
+
# end
|
69
|
+
# options = Parser.parse %w[--help]
|
70
|
+
#
|
71
|
+
# #=>
|
72
|
+
# # Usage: example.rb [options]
|
73
|
+
# # -n, --name=NAME Name to say hello to
|
74
|
+
# # -h, --help Prints this help
|
75
|
+
#
|
76
|
+
# ### Required Arguments
|
77
|
+
#
|
78
|
+
# For options that require an argument, option specification strings may include
|
79
|
+
# an option name in all caps. If an option is used without the required
|
80
|
+
# argument, an exception will be raised.
|
81
|
+
#
|
82
|
+
# require 'optparse'
|
83
|
+
#
|
84
|
+
# options = {}
|
85
|
+
# OptionParser.new do |parser|
|
86
|
+
# parser.on("-r", "--require LIBRARY",
|
87
|
+
# "Require the LIBRARY before executing your script") do |lib|
|
88
|
+
# puts "You required #{lib}!"
|
89
|
+
# end
|
90
|
+
# end.parse!
|
91
|
+
#
|
92
|
+
# Used:
|
93
|
+
#
|
94
|
+
# $ ruby optparse-test.rb -r
|
95
|
+
# optparse-test.rb:9:in `<main>': missing argument: -r (OptionParser::MissingArgument)
|
96
|
+
# $ ruby optparse-test.rb -r my-library
|
97
|
+
# You required my-library!
|
98
|
+
#
|
99
|
+
# ### Type Coercion
|
100
|
+
#
|
101
|
+
# OptionParser supports the ability to coerce command line arguments into
|
102
|
+
# objects for us.
|
103
|
+
#
|
104
|
+
# OptionParser comes with a few ready-to-use kinds of type coercion. They are:
|
105
|
+
#
|
106
|
+
# * Date -- Anything accepted by `Date.parse`
|
107
|
+
# * DateTime -- Anything accepted by `DateTime.parse`
|
108
|
+
# * Time -- Anything accepted by `Time.httpdate` or `Time.parse`
|
109
|
+
# * URI -- Anything accepted by `URI.parse`
|
110
|
+
# * Shellwords -- Anything accepted by `Shellwords.shellwords`
|
111
|
+
# * String -- Any non-empty string
|
112
|
+
# * Integer -- Any integer. Will convert octal. (e.g. 124, -3, 040)
|
113
|
+
# * Float -- Any float. (e.g. 10, 3.14, -100E+13)
|
114
|
+
# * Numeric -- Any integer, float, or rational (1, 3.4, 1/3)
|
115
|
+
# * DecimalInteger -- Like `Integer`, but no octal format.
|
116
|
+
# * OctalInteger -- Like `Integer`, but no decimal format.
|
117
|
+
# * DecimalNumeric -- Decimal integer or float.
|
118
|
+
# * TrueClass -- Accepts '+, yes, true, -, no, false' and defaults as `true`
|
119
|
+
# * FalseClass -- Same as `TrueClass`, but defaults to `false`
|
120
|
+
# * Array -- Strings separated by ',' (e.g. 1,2,3)
|
121
|
+
# * Regexp -- Regular expressions. Also includes options.
|
122
|
+
#
|
123
|
+
#
|
124
|
+
# We can also add our own coercions, which we will cover below.
|
125
|
+
#
|
126
|
+
# #### Using Built-in Conversions
|
127
|
+
#
|
128
|
+
# As an example, the built-in `Time` conversion is used. The other built-in
|
129
|
+
# conversions behave in the same way. OptionParser will attempt to parse the
|
130
|
+
# argument as a `Time`. If it succeeds, that time will be passed to the handler
|
131
|
+
# block. Otherwise, an exception will be raised.
|
132
|
+
#
|
133
|
+
# require 'optparse'
|
134
|
+
# require 'optparse/time'
|
135
|
+
# OptionParser.new do |parser|
|
136
|
+
# parser.on("-t", "--time [TIME]", Time, "Begin execution at given time") do |time|
|
137
|
+
# p time
|
138
|
+
# end
|
139
|
+
# end.parse!
|
140
|
+
#
|
141
|
+
# Used:
|
142
|
+
#
|
143
|
+
# $ ruby optparse-test.rb -t nonsense
|
144
|
+
# ... invalid argument: -t nonsense (OptionParser::InvalidArgument)
|
145
|
+
# $ ruby optparse-test.rb -t 10-11-12
|
146
|
+
# 2010-11-12 00:00:00 -0500
|
147
|
+
# $ ruby optparse-test.rb -t 9:30
|
148
|
+
# 2014-08-13 09:30:00 -0400
|
149
|
+
#
|
150
|
+
# #### Creating Custom Conversions
|
151
|
+
#
|
152
|
+
# The `accept` method on OptionParser may be used to create converters. It
|
153
|
+
# specifies which conversion block to call whenever a class is specified. The
|
154
|
+
# example below uses it to fetch a `User` object before the `on` handler
|
155
|
+
# receives it.
|
156
|
+
#
|
157
|
+
# require 'optparse'
|
158
|
+
#
|
159
|
+
# User = Struct.new(:id, :name)
|
160
|
+
#
|
161
|
+
# def find_user id
|
162
|
+
# not_found = ->{ raise "No User Found for id #{id}" }
|
163
|
+
# [ User.new(1, "Sam"),
|
164
|
+
# User.new(2, "Gandalf") ].find(not_found) do |u|
|
165
|
+
# u.id == id
|
166
|
+
# end
|
167
|
+
# end
|
168
|
+
#
|
169
|
+
# op = OptionParser.new
|
170
|
+
# op.accept(User) do |user_id|
|
171
|
+
# find_user user_id.to_i
|
172
|
+
# end
|
173
|
+
#
|
174
|
+
# op.on("--user ID", User) do |user|
|
175
|
+
# puts user
|
176
|
+
# end
|
177
|
+
#
|
178
|
+
# op.parse!
|
179
|
+
#
|
180
|
+
# Used:
|
181
|
+
#
|
182
|
+
# $ ruby optparse-test.rb --user 1
|
183
|
+
# #<struct User id=1, name="Sam">
|
184
|
+
# $ ruby optparse-test.rb --user 2
|
185
|
+
# #<struct User id=2, name="Gandalf">
|
186
|
+
# $ ruby optparse-test.rb --user 3
|
187
|
+
# optparse-test.rb:15:in `block in find_user': No User Found for id 3 (RuntimeError)
|
188
|
+
#
|
189
|
+
# ### Store options to a Hash
|
190
|
+
#
|
191
|
+
# The `into` option of `order`, `parse` and so on methods stores command line
|
192
|
+
# options into a Hash.
|
193
|
+
#
|
194
|
+
# require 'optparse'
|
195
|
+
#
|
196
|
+
# options = {}
|
197
|
+
# OptionParser.new do |parser|
|
198
|
+
# parser.on('-a')
|
199
|
+
# parser.on('-b NUM', Integer)
|
200
|
+
# parser.on('-v', '--verbose')
|
201
|
+
# end.parse!(into: options)
|
202
|
+
#
|
203
|
+
# p options
|
204
|
+
#
|
205
|
+
# Used:
|
206
|
+
#
|
207
|
+
# $ ruby optparse-test.rb -a
|
208
|
+
# {:a=>true}
|
209
|
+
# $ ruby optparse-test.rb -a -v
|
210
|
+
# {:a=>true, :verbose=>true}
|
211
|
+
# $ ruby optparse-test.rb -a -b 100
|
212
|
+
# {:a=>true, :b=>100}
|
213
|
+
#
|
214
|
+
# ### Complete example
|
215
|
+
#
|
216
|
+
# The following example is a complete Ruby program. You can run it and see the
|
217
|
+
# effect of specifying various options. This is probably the best way to learn
|
218
|
+
# the features of `optparse`.
|
219
|
+
#
|
220
|
+
# require 'optparse'
|
221
|
+
# require 'optparse/time'
|
222
|
+
# require 'ostruct'
|
223
|
+
# require 'pp'
|
224
|
+
#
|
225
|
+
# class OptparseExample
|
226
|
+
# Version = '1.0.0'
|
227
|
+
#
|
228
|
+
# CODES = %w[iso-2022-jp shift_jis euc-jp utf8 binary]
|
229
|
+
# CODE_ALIASES = { "jis" => "iso-2022-jp", "sjis" => "shift_jis" }
|
230
|
+
#
|
231
|
+
# class ScriptOptions
|
232
|
+
# attr_accessor :library, :inplace, :encoding, :transfer_type,
|
233
|
+
# :verbose, :extension, :delay, :time, :record_separator,
|
234
|
+
# :list
|
235
|
+
#
|
236
|
+
# def initialize
|
237
|
+
# self.library = []
|
238
|
+
# self.inplace = false
|
239
|
+
# self.encoding = "utf8"
|
240
|
+
# self.transfer_type = :auto
|
241
|
+
# self.verbose = false
|
242
|
+
# end
|
243
|
+
#
|
244
|
+
# def define_options(parser)
|
245
|
+
# parser.banner = "Usage: example.rb [options]"
|
246
|
+
# parser.separator ""
|
247
|
+
# parser.separator "Specific options:"
|
248
|
+
#
|
249
|
+
# # add additional options
|
250
|
+
# perform_inplace_option(parser)
|
251
|
+
# delay_execution_option(parser)
|
252
|
+
# execute_at_time_option(parser)
|
253
|
+
# specify_record_separator_option(parser)
|
254
|
+
# list_example_option(parser)
|
255
|
+
# specify_encoding_option(parser)
|
256
|
+
# optional_option_argument_with_keyword_completion_option(parser)
|
257
|
+
# boolean_verbose_option(parser)
|
258
|
+
#
|
259
|
+
# parser.separator ""
|
260
|
+
# parser.separator "Common options:"
|
261
|
+
# # No argument, shows at tail. This will print an options summary.
|
262
|
+
# # Try it and see!
|
263
|
+
# parser.on_tail("-h", "--help", "Show this message") do
|
264
|
+
# puts parser
|
265
|
+
# exit
|
266
|
+
# end
|
267
|
+
# # Another typical switch to print the version.
|
268
|
+
# parser.on_tail("--version", "Show version") do
|
269
|
+
# puts Version
|
270
|
+
# exit
|
271
|
+
# end
|
272
|
+
# end
|
273
|
+
#
|
274
|
+
# def perform_inplace_option(parser)
|
275
|
+
# # Specifies an optional option argument
|
276
|
+
# parser.on("-i", "--inplace [EXTENSION]",
|
277
|
+
# "Edit ARGV files in place",
|
278
|
+
# "(make backup if EXTENSION supplied)") do |ext|
|
279
|
+
# self.inplace = true
|
280
|
+
# self.extension = ext || ''
|
281
|
+
# self.extension.sub!(/\A\.?(?=.)/, ".") # Ensure extension begins with dot.
|
282
|
+
# end
|
283
|
+
# end
|
284
|
+
#
|
285
|
+
# def delay_execution_option(parser)
|
286
|
+
# # Cast 'delay' argument to a Float.
|
287
|
+
# parser.on("--delay N", Float, "Delay N seconds before executing") do |n|
|
288
|
+
# self.delay = n
|
289
|
+
# end
|
290
|
+
# end
|
291
|
+
#
|
292
|
+
# def execute_at_time_option(parser)
|
293
|
+
# # Cast 'time' argument to a Time object.
|
294
|
+
# parser.on("-t", "--time [TIME]", Time, "Begin execution at given time") do |time|
|
295
|
+
# self.time = time
|
296
|
+
# end
|
297
|
+
# end
|
298
|
+
#
|
299
|
+
# def specify_record_separator_option(parser)
|
300
|
+
# # Cast to octal integer.
|
301
|
+
# parser.on("-F", "--irs [OCTAL]", OptionParser::OctalInteger,
|
302
|
+
# "Specify record separator (default \\0)") do |rs|
|
303
|
+
# self.record_separator = rs
|
304
|
+
# end
|
305
|
+
# end
|
306
|
+
#
|
307
|
+
# def list_example_option(parser)
|
308
|
+
# # List of arguments.
|
309
|
+
# parser.on("--list x,y,z", Array, "Example 'list' of arguments") do |list|
|
310
|
+
# self.list = list
|
311
|
+
# end
|
312
|
+
# end
|
313
|
+
#
|
314
|
+
# def specify_encoding_option(parser)
|
315
|
+
# # Keyword completion. We are specifying a specific set of arguments (CODES
|
316
|
+
# # and CODE_ALIASES - notice the latter is a Hash), and the user may provide
|
317
|
+
# # the shortest unambiguous text.
|
318
|
+
# code_list = (CODE_ALIASES.keys + CODES).join(', ')
|
319
|
+
# parser.on("--code CODE", CODES, CODE_ALIASES, "Select encoding",
|
320
|
+
# "(#{code_list})") do |encoding|
|
321
|
+
# self.encoding = encoding
|
322
|
+
# end
|
323
|
+
# end
|
324
|
+
#
|
325
|
+
# def optional_option_argument_with_keyword_completion_option(parser)
|
326
|
+
# # Optional '--type' option argument with keyword completion.
|
327
|
+
# parser.on("--type [TYPE]", [:text, :binary, :auto],
|
328
|
+
# "Select transfer type (text, binary, auto)") do |t|
|
329
|
+
# self.transfer_type = t
|
330
|
+
# end
|
331
|
+
# end
|
332
|
+
#
|
333
|
+
# def boolean_verbose_option(parser)
|
334
|
+
# # Boolean switch.
|
335
|
+
# parser.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
336
|
+
# self.verbose = v
|
337
|
+
# end
|
338
|
+
# end
|
339
|
+
# end
|
340
|
+
#
|
341
|
+
# #
|
342
|
+
# # Return a structure describing the options.
|
343
|
+
# #
|
344
|
+
# def parse(args)
|
345
|
+
# # The options specified on the command line will be collected in
|
346
|
+
# # *options*.
|
347
|
+
#
|
348
|
+
# @options = ScriptOptions.new
|
349
|
+
# @args = OptionParser.new do |parser|
|
350
|
+
# @options.define_options(parser)
|
351
|
+
# parser.parse!(args)
|
352
|
+
# end
|
353
|
+
# @options
|
354
|
+
# end
|
355
|
+
#
|
356
|
+
# attr_reader :parser, :options
|
357
|
+
# end # class OptparseExample
|
358
|
+
#
|
359
|
+
# example = OptparseExample.new
|
360
|
+
# options = example.parse(ARGV)
|
361
|
+
# pp options # example.options
|
362
|
+
# pp ARGV
|
363
|
+
#
|
364
|
+
# ### Shell Completion
|
365
|
+
#
|
366
|
+
# For modern shells (e.g. bash, zsh, etc.), you can use shell completion for
|
367
|
+
# command line options.
|
368
|
+
#
|
369
|
+
# ### Further documentation
|
370
|
+
#
|
371
|
+
# The above examples should be enough to learn how to use this class. If you
|
372
|
+
# have any questions, file a ticket at http://bugs.ruby-lang.org.
|
373
|
+
class OptionParser
|
374
|
+
interface _Pattern
|
375
|
+
def match: (untyped other) -> boolish
|
376
|
+
end
|
377
|
+
|
378
|
+
interface _Intoable
|
379
|
+
def []=: (Symbol, untyped) -> untyped
|
380
|
+
end
|
381
|
+
|
382
|
+
interface _LtLtString
|
383
|
+
def <<: (String) -> untyped
|
384
|
+
end
|
385
|
+
|
386
|
+
# See #accept.
|
387
|
+
#
|
388
|
+
def self.accept: (Class t, ?_Pattern pat) ?{ (*untyped) -> untyped } -> void
|
389
|
+
|
390
|
+
# See #getopts.
|
391
|
+
#
|
392
|
+
def self.getopts: (*String options) -> Hash[String, untyped]
|
393
|
+
| (Array[String] args, *String options) -> Hash[String, untyped]
|
394
|
+
|
395
|
+
# Returns an incremented value of `default` according to `arg`.
|
396
|
+
#
|
397
|
+
def self.inc: (untyped arg, ?_ToI default) -> Integer?
|
398
|
+
|
399
|
+
# See #reject.
|
400
|
+
#
|
401
|
+
def self.reject: (Class t) -> void
|
402
|
+
|
403
|
+
def self.terminate: (?String arg) -> bot
|
404
|
+
|
405
|
+
def self.top: () -> OptionParser::List
|
406
|
+
|
407
|
+
# Initializes a new instance and evaluates the optional block in context of the
|
408
|
+
# instance. Arguments `args` are passed to #new, see there for description of
|
409
|
+
# parameters.
|
410
|
+
#
|
411
|
+
# This method is **deprecated**, its behavior corresponds to the older #new
|
412
|
+
# method.
|
413
|
+
#
|
414
|
+
def self.with: (?String banner, ?Integer width, ?String indent) ?{ (instance opts) -> void } -> instance
|
415
|
+
|
416
|
+
public
|
417
|
+
|
418
|
+
def abort: (?_ToS mesg) -> bot
|
419
|
+
|
420
|
+
# Directs to accept specified class `t`. The argument string is passed to the
|
421
|
+
# block in which it should be converted to the desired class.
|
422
|
+
#
|
423
|
+
# `t`
|
424
|
+
# : Argument class specifier, any object including Class.
|
425
|
+
# `pat`
|
426
|
+
# : Pattern for argument, defaults to `t` if it responds to match.
|
427
|
+
#
|
428
|
+
#
|
429
|
+
# accept(t, pat, &block)
|
430
|
+
#
|
431
|
+
def accept: (Class t, ?_Pattern pat) ?{ (*untyped) -> untyped } -> void
|
432
|
+
|
433
|
+
def add_officious: () -> void
|
434
|
+
|
435
|
+
# Returns additional info.
|
436
|
+
#
|
437
|
+
def additional_message: (untyped typ, untyped opt) -> String?
|
438
|
+
|
439
|
+
# Heading banner preceding summary.
|
440
|
+
#
|
441
|
+
attr_accessor banner: String
|
442
|
+
|
443
|
+
# Subject of #on_tail.
|
444
|
+
#
|
445
|
+
def base: () -> List
|
446
|
+
|
447
|
+
def candidate: (String word) -> Array[untyped]
|
448
|
+
|
449
|
+
def compsys: (untyped to, ?untyped name) -> untyped
|
450
|
+
|
451
|
+
alias def_head_option define_head
|
452
|
+
|
453
|
+
alias def_option define
|
454
|
+
|
455
|
+
alias def_tail_option define_tail
|
456
|
+
|
457
|
+
# Strings to be parsed in default.
|
458
|
+
#
|
459
|
+
attr_accessor default_argv: Array[String]
|
460
|
+
|
461
|
+
# Creates an option from the given parameters `params`. See [Parameters for New
|
462
|
+
# Options](./option_params_rdoc.html).
|
463
|
+
#
|
464
|
+
# The block, if given, is the handler for the created option. When the option is
|
465
|
+
# encountered during command-line parsing, the block is called with the argument
|
466
|
+
# given for the option, if any. See [Option
|
467
|
+
# Handlers](./option_params_rdoc.html#label-Option+Handlers).
|
468
|
+
#
|
469
|
+
def define: (*String params) ?{ (*untyped) -> untyped } -> untyped
|
470
|
+
| (String params, Class | Array[String] | Hash[Symbol, untyped] | Regexp obj, ?String desc) ?{ (*untyped) -> untyped } -> untyped
|
471
|
+
| (*String params, Proc | Method handler) -> untyped
|
472
|
+
| (String params, Class | Array[String] | Hash[Symbol, untyped] | Regexp obj, ?String desc, Proc | Method handler) -> untyped
|
473
|
+
|
474
|
+
# Creates an option from the given parameters `params`. See [Parameters for New
|
475
|
+
# Options](./option_params_rdoc.html).
|
476
|
+
#
|
477
|
+
# The block, if given, is the handler for the created option. When the option is
|
478
|
+
# encountered during command-line parsing, the block is called with the argument
|
479
|
+
# given for the option, if any. See [Option
|
480
|
+
# Handlers](./option_params_rdoc.html#label-Option+Handlers).
|
481
|
+
#
|
482
|
+
def define_head: (*String params) ?{ (*untyped) -> untyped } -> untyped
|
483
|
+
| (String params, Class | Array[String] | Hash[Symbol, untyped] | Regexp obj, ?String desc) ?{ (*untyped) -> untyped } -> untyped
|
484
|
+
| (*String params, Proc | Method handler) -> untyped
|
485
|
+
| (String params, Class | Array[String] | Hash[Symbol, untyped] | Regexp obj, ?String desc, Proc | Method handler) -> untyped
|
486
|
+
|
487
|
+
# Creates an option from the given parameters `params`. See [Parameters for New
|
488
|
+
# Options](./option_params_rdoc.html).
|
489
|
+
#
|
490
|
+
# The block, if given, is the handler for the created option. When the option is
|
491
|
+
# encountered during command-line parsing, the block is called with the argument
|
492
|
+
# given for the option, if any. See [Option
|
493
|
+
# Handlers](./option_params_rdoc.html#label-Option+Handlers).
|
494
|
+
#
|
495
|
+
def define_tail: (*String params) ?{ (*untyped) -> untyped } -> untyped
|
496
|
+
| (String params, Class | Array[String] | Hash[Symbol, untyped] | Regexp obj, ?String desc) ?{ (*untyped) -> untyped } -> untyped
|
497
|
+
| (*String params, Proc | Method handler) -> untyped
|
498
|
+
| (String params, Class | Array[String] | Hash[Symbol, untyped] | Regexp obj, ?String desc, Proc | Method handler) -> untyped
|
499
|
+
|
500
|
+
# Parses environment variable `env` or its uppercase with splitting like a
|
501
|
+
# shell.
|
502
|
+
#
|
503
|
+
# `env` defaults to the basename of the program.
|
504
|
+
#
|
505
|
+
def environment: (?String env) -> Array[String]?
|
506
|
+
|
507
|
+
# Wrapper method for getopts.rb.
|
508
|
+
#
|
509
|
+
# params = ARGV.getopts("ab:", "foo", "bar:", "zot:Z;zot option")
|
510
|
+
# # params["a"] = true # -a
|
511
|
+
# # params["b"] = "1" # -b1
|
512
|
+
# # params["foo"] = "1" # --foo
|
513
|
+
# # params["bar"] = "x" # --bar x
|
514
|
+
# # params["zot"] = "z" # --zot Z
|
515
|
+
#
|
516
|
+
def getopts: (*String options) -> Hash[String, untyped]
|
517
|
+
| (Array[String] args, *String options) -> Hash[String, untyped]
|
518
|
+
|
519
|
+
# Returns option summary string.
|
520
|
+
#
|
521
|
+
def help: () -> String
|
522
|
+
|
523
|
+
def inc: (*untyped args) -> untyped
|
524
|
+
|
525
|
+
# Loads options from file names as `filename`. Does nothing when the file is not
|
526
|
+
# present. Returns whether successfully loaded.
|
527
|
+
#
|
528
|
+
# `filename` defaults to basename of the program without suffix in a directory
|
529
|
+
# ~/.options, then the basename with '.options' suffix under XDG and Haiku
|
530
|
+
# standard places.
|
531
|
+
#
|
532
|
+
def load: (?String filename) -> bool
|
533
|
+
|
534
|
+
# Creates an option from the given parameters `params`. See [Parameters for New
|
535
|
+
# Options](./option_params_rdoc.html).
|
536
|
+
#
|
537
|
+
# The block, if given, is the handler for the created option. When the option is
|
538
|
+
# encountered during command-line parsing, the block is called with the argument
|
539
|
+
# given for the option, if any. See [Option
|
540
|
+
# Handlers](./option_params_rdoc.html#label-Option+Handlers).
|
541
|
+
#
|
542
|
+
def make_switch: (Array[untyped] opts, ?Proc block) -> [untyped, untyped, untyped, untyped, untyped]
|
543
|
+
|
544
|
+
# Pushes a new List.
|
545
|
+
#
|
546
|
+
def new: () -> self
|
547
|
+
| [T] () { (self) -> T } -> T
|
548
|
+
|
549
|
+
# Creates an option from the given parameters `params`. See [Parameters for New
|
550
|
+
# Options](./option_params_rdoc.html).
|
551
|
+
#
|
552
|
+
# The block, if given, is the handler for the created option. When the option is
|
553
|
+
# encountered during command-line parsing, the block is called with the argument
|
554
|
+
# given for the option, if any. See [Option
|
555
|
+
# Handlers](./option_params_rdoc.html#label-Option+Handlers).
|
556
|
+
#
|
557
|
+
def on: (*String params) ?{ (*untyped) -> untyped } -> self
|
558
|
+
| (String params, Class | Array[String] | Hash[Symbol, untyped] | Regexp obj, ?String desc) ?{ (*untyped) -> untyped } -> self
|
559
|
+
| (*String params, Proc | Method handler) -> self
|
560
|
+
| (String params, Class | Array[String] | Hash[Symbol, untyped] | Regexp obj, ?String desc, Proc | Method handler) -> self
|
561
|
+
|
562
|
+
|
563
|
+
# Creates an option from the given parameters `params`. See [Parameters for New
|
564
|
+
# Options](./option_params_rdoc.html).
|
565
|
+
#
|
566
|
+
# The block, if given, is the handler for the created option. When the option is
|
567
|
+
# encountered during command-line parsing, the block is called with the argument
|
568
|
+
# given for the option, if any. See [Option
|
569
|
+
# Handlers](./option_params_rdoc.html#label-Option+Handlers).
|
570
|
+
#
|
571
|
+
# The new option is added at the head of the summary.
|
572
|
+
#
|
573
|
+
def on_head: (*String params) ?{ (*untyped) -> untyped } -> self
|
574
|
+
| (String params, Class | Array[String] | Hash[Symbol, untyped] | Regexp obj, ?String desc) ?{ (*untyped) -> untyped } -> self
|
575
|
+
| (*String params, Proc | Method handler) -> self
|
576
|
+
| (String params, Class | Array[String] | Hash[Symbol, untyped] | Regexp obj, ?String desc, Proc | Method handler) -> self
|
577
|
+
|
578
|
+
# Creates an option from the given parameters `params`. See [Parameters for New
|
579
|
+
# Options](./option_params_rdoc.html).
|
580
|
+
#
|
581
|
+
# The block, if given, is the handler for the created option. When the option is
|
582
|
+
# encountered during command-line parsing, the block is called with the argument
|
583
|
+
# given for the option, if any. See [Option
|
584
|
+
# Handlers](./option_params_rdoc.html#label-Option+Handlers).
|
585
|
+
#
|
586
|
+
# The new option is added at the tail of the summary.
|
587
|
+
#
|
588
|
+
def on_tail: (*String params) ?{ (*untyped) -> untyped } -> self
|
589
|
+
| (String params, Class | Array[String] | Hash[Symbol, untyped] | Regexp obj, ?String desc) ?{ (*untyped) -> untyped } -> self
|
590
|
+
| (*String params, Proc | Method handler) -> self
|
591
|
+
| (String params, Class | Array[String] | Hash[Symbol, untyped] | Regexp obj, ?String desc, Proc | Method handler) -> self
|
592
|
+
|
593
|
+
# Parses command line arguments `argv` in order. When a block is given, each
|
594
|
+
# non-option argument is yielded. When optional `into` keyword argument is
|
595
|
+
# provided, the parsed option values are stored there via `[]=` method (so it
|
596
|
+
# can be Hash, or OpenStruct, or other similar object).
|
597
|
+
#
|
598
|
+
# Returns the rest of `argv` left unparsed.
|
599
|
+
#
|
600
|
+
def order: (*String argv, ?into: _Intoable) ?{ (String) -> void } -> Array[String]
|
601
|
+
| (Array[String] argv, ?into: _Intoable) ?{ (String) -> void } -> Array[String]
|
602
|
+
|
603
|
+
# Same as #order, but removes switches destructively. Non-option arguments
|
604
|
+
# remain in `argv`.
|
605
|
+
#
|
606
|
+
def order!: (?Array[String] argv, ?into: _Intoable) ?{ (String) -> void } -> Array[String]
|
607
|
+
|
608
|
+
# Parses command line arguments `argv` in order when environment variable
|
609
|
+
# POSIXLY_CORRECT is set, and in permutation mode otherwise. When optional
|
610
|
+
# `into` keyword argument is provided, the parsed option values are stored there
|
611
|
+
# via `[]=` method (so it can be Hash, or OpenStruct, or other similar object).
|
612
|
+
#
|
613
|
+
def parse: (*String argv, ?into: _Intoable) -> Array[String]
|
614
|
+
| (Array[String] argv, ?into: _Intoable) -> Array[String]
|
615
|
+
|
616
|
+
# Same as #parse, but removes switches destructively. Non-option arguments
|
617
|
+
# remain in `argv`.
|
618
|
+
#
|
619
|
+
def parse!: (?Array[String] argv, ?into: _Intoable) -> Array[String]
|
620
|
+
|
621
|
+
# Parses command line arguments `argv` in permutation mode and returns list of
|
622
|
+
# non-option arguments. When optional `into` keyword argument is provided, the
|
623
|
+
# parsed option values are stored there via `[]=` method (so it can be Hash, or
|
624
|
+
# OpenStruct, or other similar object).
|
625
|
+
#
|
626
|
+
def permute: (*String argv, ?into: _Intoable) -> Array[String]
|
627
|
+
| (Array[String] argv, ?into: _Intoable) -> Array[String]
|
628
|
+
|
629
|
+
# Same as #permute, but removes switches destructively. Non-option arguments
|
630
|
+
# remain in `argv`.
|
631
|
+
#
|
632
|
+
def permute!: (?Array[String] argv, ?into: _Intoable) -> Array[String]
|
633
|
+
|
634
|
+
# Program name to be emitted in error message and default banner, defaults to
|
635
|
+
# $0.
|
636
|
+
#
|
637
|
+
attr_accessor program_name: String
|
638
|
+
|
639
|
+
# Directs to reject specified class argument.
|
640
|
+
#
|
641
|
+
# `t`
|
642
|
+
# : Argument class specifier, any object including Class.
|
643
|
+
#
|
644
|
+
#
|
645
|
+
# reject(t)
|
646
|
+
#
|
647
|
+
def reject: (Class t) -> void
|
648
|
+
|
649
|
+
# Release code
|
650
|
+
#
|
651
|
+
def release: () -> untyped
|
652
|
+
|
653
|
+
def release=: (untyped) -> untyped
|
654
|
+
|
655
|
+
# Removes the last List.
|
656
|
+
#
|
657
|
+
def remove: () -> List?
|
658
|
+
|
659
|
+
# Whether to require that options match exactly (disallows providing abbreviated
|
660
|
+
# long option as short option).
|
661
|
+
#
|
662
|
+
attr_accessor require_exact: boolish
|
663
|
+
|
664
|
+
# Add separator in summary.
|
665
|
+
#
|
666
|
+
def separator: (String string) -> void
|
667
|
+
|
668
|
+
# Heading banner preceding summary.
|
669
|
+
#
|
670
|
+
alias set_banner banner=
|
671
|
+
|
672
|
+
# Program name to be emitted in error message and default banner, defaults to
|
673
|
+
# $0.
|
674
|
+
#
|
675
|
+
alias set_program_name program_name=
|
676
|
+
|
677
|
+
# Indentation for summary. Must be String (or have + String method).
|
678
|
+
#
|
679
|
+
alias set_summary_indent summary_indent=
|
680
|
+
|
681
|
+
# Width for option list portion of summary. Must be Numeric.
|
682
|
+
#
|
683
|
+
alias set_summary_width summary_width=
|
684
|
+
|
685
|
+
# Puts option summary into `to` and returns `to`. Yields each line if a block is
|
686
|
+
# given.
|
687
|
+
#
|
688
|
+
# `to`
|
689
|
+
# : Output destination, which must have method <<. Defaults to [].
|
690
|
+
# `width`
|
691
|
+
# : Width of left side, defaults to @summary_width.
|
692
|
+
# `max`
|
693
|
+
# : Maximum length allowed for left side, defaults to `width` - 1.
|
694
|
+
# `indent`
|
695
|
+
# : Indentation, defaults to @summary_indent.
|
696
|
+
#
|
697
|
+
#
|
698
|
+
def summarize: (?_LtLtString to, ?Integer width, ?Integer max, ?String indent) ?{ (String line) -> void } -> _LtLtString
|
699
|
+
|
700
|
+
# Indentation for summary. Must be String (or have + String method).
|
701
|
+
#
|
702
|
+
attr_accessor summary_indent: String
|
703
|
+
|
704
|
+
# Width for option list portion of summary. Must be Numeric.
|
705
|
+
#
|
706
|
+
attr_accessor summary_width: Integer
|
707
|
+
|
708
|
+
# Terminates option parsing. Optional parameter `arg` is a string pushed back to
|
709
|
+
# be the first non-option argument.
|
710
|
+
#
|
711
|
+
def terminate: (?String arg) -> bot
|
712
|
+
|
713
|
+
# Returns option summary list.
|
714
|
+
#
|
715
|
+
def to_a: () -> Array[String]
|
716
|
+
|
717
|
+
alias to_s help
|
718
|
+
|
719
|
+
# Subject of #on / #on_head, #accept / #reject
|
720
|
+
#
|
721
|
+
def top: () -> List
|
722
|
+
|
723
|
+
# Returns version string from program_name, version and release.
|
724
|
+
#
|
725
|
+
def ver: () -> String?
|
726
|
+
|
727
|
+
# Version
|
728
|
+
#
|
729
|
+
attr_accessor version: String?
|
730
|
+
|
731
|
+
def warn: (?_ToS mesg) -> void
|
732
|
+
|
733
|
+
private
|
734
|
+
|
735
|
+
# Completes shortened long style option switch and returns pair of canonical
|
736
|
+
# switch and switch descriptor OptionParser::Switch.
|
737
|
+
#
|
738
|
+
# `typ`
|
739
|
+
# : Searching table.
|
740
|
+
# `opt`
|
741
|
+
# : Searching key.
|
742
|
+
# `icase`
|
743
|
+
# : Search case insensitive if true.
|
744
|
+
# `pat`
|
745
|
+
# : Optional pattern for completion.
|
746
|
+
#
|
747
|
+
#
|
748
|
+
def complete: (untyped typ, untyped opt, ?untyped icase, *untyped pat) -> untyped
|
749
|
+
|
750
|
+
# Initializes the instance and yields itself if called with a block.
|
751
|
+
#
|
752
|
+
# `banner`
|
753
|
+
# : Banner message.
|
754
|
+
# `width`
|
755
|
+
# : Summary width.
|
756
|
+
# `indent`
|
757
|
+
# : Summary indent.
|
758
|
+
#
|
759
|
+
#
|
760
|
+
def initialize: (?String banner, ?Integer width, ?String indent) ?{ (OptionParser) -> void } -> void
|
761
|
+
|
762
|
+
# Checks if an argument is given twice, in which case an ArgumentError is
|
763
|
+
# raised. Called from OptionParser#switch only.
|
764
|
+
#
|
765
|
+
# `obj`
|
766
|
+
# : New argument.
|
767
|
+
# `prv`
|
768
|
+
# : Previously specified argument.
|
769
|
+
# `msg`
|
770
|
+
# : Exception message.
|
771
|
+
#
|
772
|
+
#
|
773
|
+
def notwice: (untyped obj, untyped prv, untyped msg) -> untyped
|
774
|
+
|
775
|
+
def parse_in_order: (?untyped argv, ?untyped setter) { (*untyped) -> untyped } -> untyped
|
776
|
+
|
777
|
+
# Searches `key` in @stack for `id` hash and returns or yields the result.
|
778
|
+
#
|
779
|
+
def search: (untyped id, untyped key) -> untyped
|
780
|
+
|
781
|
+
# Traverses @stack, sending each element method `id` with `args` and `block`.
|
782
|
+
#
|
783
|
+
def visit: (untyped id, *untyped args) { (*untyped) -> untyped } -> untyped
|
784
|
+
end
|
785
|
+
|
786
|
+
OptionParser::ArgumentStyle: Hash[untyped, untyped]
|
787
|
+
|
788
|
+
OptionParser::COMPSYS_HEADER: String
|
789
|
+
|
790
|
+
# Decimal integer format, to be converted to Integer.
|
791
|
+
OptionParser::DecimalInteger: Regexp
|
792
|
+
|
793
|
+
# Decimal integer/float number format, to be converted to Integer for integer
|
794
|
+
# format, Float for float format.
|
795
|
+
OptionParser::DecimalNumeric: Regexp
|
796
|
+
|
797
|
+
OptionParser::DefaultList: OptionParser::List
|
798
|
+
|
799
|
+
OptionParser::NO_ARGUMENT: Symbol
|
800
|
+
|
801
|
+
OptionParser::NoArgument: [:NONE, nil]
|
802
|
+
|
803
|
+
OptionParser::OPTIONAL_ARGUMENT: Symbol
|
804
|
+
|
805
|
+
# Ruby/C like octal/hexadecimal/binary integer format, to be converted to
|
806
|
+
# Integer.
|
807
|
+
OptionParser::OctalInteger: Regexp
|
808
|
+
|
809
|
+
OptionParser::Officious: Hash[untyped, untyped]
|
810
|
+
|
811
|
+
OptionParser::OptionalArgument: Array[untyped]
|
812
|
+
|
813
|
+
OptionParser::REQUIRED_ARGUMENT: Symbol
|
814
|
+
|
815
|
+
OptionParser::RequiredArgument: Array[untyped]
|
816
|
+
|
817
|
+
OptionParser::SPLAT_PROC: Proc
|
818
|
+
|
819
|
+
OptionParser::Version: String
|
820
|
+
|
821
|
+
# Acceptable argument classes. Now contains DecimalInteger, OctalInteger and
|
822
|
+
# DecimalNumeric. See Acceptable argument classes (in source code).
|
823
|
+
module OptionParser::Acceptables
|
824
|
+
end
|
825
|
+
|
826
|
+
OptionParser::Acceptables::DecimalInteger: Regexp
|
827
|
+
|
828
|
+
OptionParser::Acceptables::DecimalNumeric: Regexp
|
829
|
+
|
830
|
+
OptionParser::Acceptables::OctalInteger: Regexp
|
831
|
+
|
832
|
+
# Raises when the given argument word can't be completed uniquely.
|
833
|
+
class OptionParser::AmbiguousArgument < OptionParser::InvalidArgument
|
834
|
+
end
|
835
|
+
|
836
|
+
OptionParser::AmbiguousArgument::Reason: String
|
837
|
+
|
838
|
+
# Raises when ambiguously completable string is encountered.
|
839
|
+
class OptionParser::AmbiguousOption < OptionParser::ParseError
|
840
|
+
end
|
841
|
+
|
842
|
+
OptionParser::AmbiguousOption::Reason: String
|
843
|
+
|
844
|
+
# Extends command line arguments array (ARGV) to parse itself.
|
845
|
+
module OptionParser::Arguable
|
846
|
+
# Initializes instance variable.
|
847
|
+
#
|
848
|
+
def self.extend_object: (untyped obj) -> untyped
|
849
|
+
|
850
|
+
public
|
851
|
+
|
852
|
+
# Substitution of getopts is possible as follows. Also see OptionParser#getopts.
|
853
|
+
#
|
854
|
+
# def getopts(*args)
|
855
|
+
# ($OPT = ARGV.getopts(*args)).each do |opt, val|
|
856
|
+
# eval "$OPT_#{opt.gsub(/[^A-Za-z0-9_]/, '_')} = val"
|
857
|
+
# end
|
858
|
+
# rescue OptionParser::ParseError
|
859
|
+
# end
|
860
|
+
#
|
861
|
+
def getopts: (*String args) -> Hash[String, untyped]
|
862
|
+
|
863
|
+
# Actual OptionParser object, automatically created if nonexistent.
|
864
|
+
#
|
865
|
+
# If called with a block, yields the OptionParser object and returns the result
|
866
|
+
# of the block. If an OptionParser::ParseError exception occurs in the block, it
|
867
|
+
# is rescued, a error message printed to STDERR and `nil` returned.
|
868
|
+
#
|
869
|
+
def options: () -> OptionParser
|
870
|
+
| [T] () { (OptionParser) -> T } -> T?
|
871
|
+
|
872
|
+
# Sets OptionParser object, when `opt` is `false` or `nil`, methods
|
873
|
+
# OptionParser::Arguable#options and OptionParser::Arguable#options= are
|
874
|
+
# undefined. Thus, there is no ways to access the OptionParser object via the
|
875
|
+
# receiver object.
|
876
|
+
#
|
877
|
+
def options=: (OptionParser? opt) -> untyped
|
878
|
+
|
879
|
+
# Parses `self` destructively in order and returns `self` containing the rest
|
880
|
+
# arguments left unparsed.
|
881
|
+
#
|
882
|
+
def order!: () ?{ (String) -> void } -> Array[String]
|
883
|
+
|
884
|
+
# Parses `self` destructively and returns `self` containing the rest arguments
|
885
|
+
# left unparsed.
|
886
|
+
#
|
887
|
+
def parse!: () -> Array[String]
|
888
|
+
|
889
|
+
# Parses `self` destructively in permutation mode and returns `self` containing
|
890
|
+
# the rest arguments left unparsed.
|
891
|
+
#
|
892
|
+
def permute!: () -> Array[String]
|
893
|
+
end
|
894
|
+
|
895
|
+
# Hash with completion search feature. See OptionParser::Completion.
|
896
|
+
class OptionParser::CompletingHash < Hash[untyped, untyped]
|
897
|
+
include OptionParser::Completion
|
898
|
+
|
899
|
+
public
|
900
|
+
|
901
|
+
# Completion for hash key.
|
902
|
+
#
|
903
|
+
def match: (untyped key) -> untyped
|
904
|
+
end
|
905
|
+
|
906
|
+
# Keyword completion module. This allows partial arguments to be specified and
|
907
|
+
# resolved against a list of acceptable values.
|
908
|
+
module OptionParser::Completion
|
909
|
+
def self.candidate: (untyped key, ?untyped icase, ?untyped pat) { (*untyped) -> untyped } -> untyped
|
910
|
+
|
911
|
+
def self.regexp: (untyped key, untyped icase) -> untyped
|
912
|
+
|
913
|
+
public
|
914
|
+
|
915
|
+
def candidate: (untyped key, ?untyped icase, ?untyped pat) -> untyped
|
916
|
+
|
917
|
+
def complete: (untyped key, ?untyped icase, ?untyped pat) -> untyped
|
918
|
+
|
919
|
+
def convert: (?untyped opt, ?untyped val, *untyped) -> untyped
|
920
|
+
end
|
921
|
+
|
922
|
+
# Raises when the given argument does not match required format.
|
923
|
+
class OptionParser::InvalidArgument < OptionParser::ParseError
|
924
|
+
end
|
925
|
+
|
926
|
+
OptionParser::InvalidArgument::Reason: String
|
927
|
+
|
928
|
+
# Raises when switch is undefined.
|
929
|
+
class OptionParser::InvalidOption < OptionParser::ParseError
|
930
|
+
end
|
931
|
+
|
932
|
+
OptionParser::InvalidOption::Reason: String
|
933
|
+
|
934
|
+
# Simple option list providing mapping from short and/or long option string to
|
935
|
+
# OptionParser::Switch and mapping from acceptable argument to matching pattern
|
936
|
+
# and converter pair. Also provides summary feature.
|
937
|
+
class OptionParser::List
|
938
|
+
public
|
939
|
+
|
940
|
+
# See OptionParser.accept.
|
941
|
+
#
|
942
|
+
def accept: (untyped t, ?untyped pat) { (*untyped) -> untyped } -> untyped
|
943
|
+
|
944
|
+
def add_banner: (untyped to) -> untyped
|
945
|
+
|
946
|
+
# Appends `switch` at the tail of the list, and associates short, long and
|
947
|
+
# negated long options. Arguments are:
|
948
|
+
#
|
949
|
+
# `switch`
|
950
|
+
# : OptionParser::Switch instance to be inserted.
|
951
|
+
# `short_opts`
|
952
|
+
# : List of short style options.
|
953
|
+
# `long_opts`
|
954
|
+
# : List of long style options.
|
955
|
+
# `nolong_opts`
|
956
|
+
# : List of long style options with "no-" prefix.
|
957
|
+
#
|
958
|
+
#
|
959
|
+
# append(switch, short_opts, long_opts, nolong_opts)
|
960
|
+
#
|
961
|
+
def append: (*untyped args) -> untyped
|
962
|
+
|
963
|
+
# Map from acceptable argument types to pattern and converter pairs.
|
964
|
+
#
|
965
|
+
def atype: () -> untyped
|
966
|
+
|
967
|
+
# Searches list `id` for `opt` and the optional patterns for completion `pat`.
|
968
|
+
# If `icase` is true, the search is case insensitive. The result is returned or
|
969
|
+
# yielded if a block is given. If it isn't found, nil is returned.
|
970
|
+
#
|
971
|
+
def complete: (untyped id, untyped opt, ?untyped icase, *untyped pat) { (*untyped) -> untyped } -> untyped
|
972
|
+
|
973
|
+
def compsys: (*untyped args) { (*untyped) -> untyped } -> untyped
|
974
|
+
|
975
|
+
# Iterates over each option, passing the option to the `block`.
|
976
|
+
#
|
977
|
+
def each_option: () { (*untyped) -> untyped } -> untyped
|
978
|
+
|
979
|
+
def get_candidates: (untyped id) -> untyped
|
980
|
+
|
981
|
+
# List of all switches and summary string.
|
982
|
+
#
|
983
|
+
def list: () -> untyped
|
984
|
+
|
985
|
+
# Map from long style option switches to actual switch objects.
|
986
|
+
#
|
987
|
+
def long: () -> untyped
|
988
|
+
|
989
|
+
# Inserts `switch` at the head of the list, and associates short, long and
|
990
|
+
# negated long options. Arguments are:
|
991
|
+
#
|
992
|
+
# `switch`
|
993
|
+
# : OptionParser::Switch instance to be inserted.
|
994
|
+
# `short_opts`
|
995
|
+
# : List of short style options.
|
996
|
+
# `long_opts`
|
997
|
+
# : List of long style options.
|
998
|
+
# `nolong_opts`
|
999
|
+
# : List of long style options with "no-" prefix.
|
1000
|
+
#
|
1001
|
+
#
|
1002
|
+
# prepend(switch, short_opts, long_opts, nolong_opts)
|
1003
|
+
#
|
1004
|
+
def prepend: (*untyped args) -> untyped
|
1005
|
+
|
1006
|
+
# See OptionParser.reject.
|
1007
|
+
#
|
1008
|
+
def reject: (untyped t) -> untyped
|
1009
|
+
|
1010
|
+
# Searches `key` in `id` list. The result is returned or yielded if a block is
|
1011
|
+
# given. If it isn't found, nil is returned.
|
1012
|
+
#
|
1013
|
+
def search: (untyped id, untyped key) -> untyped
|
1014
|
+
|
1015
|
+
# Map from short style option switches to actual switch objects.
|
1016
|
+
#
|
1017
|
+
def short: () -> untyped
|
1018
|
+
|
1019
|
+
# Creates the summary table, passing each line to the `block` (without newline).
|
1020
|
+
# The arguments `args` are passed along to the summarize method which is called
|
1021
|
+
# on every option.
|
1022
|
+
#
|
1023
|
+
def summarize: (*untyped args) { (*untyped) -> untyped } -> untyped
|
1024
|
+
|
1025
|
+
private
|
1026
|
+
|
1027
|
+
# Just initializes all instance variables.
|
1028
|
+
#
|
1029
|
+
def initialize: () -> void
|
1030
|
+
|
1031
|
+
# Adds `sw` according to `sopts`, `lopts` and `nlopts`.
|
1032
|
+
#
|
1033
|
+
# `sw`
|
1034
|
+
# : OptionParser::Switch instance to be added.
|
1035
|
+
# `sopts`
|
1036
|
+
# : Short style option list.
|
1037
|
+
# `lopts`
|
1038
|
+
# : Long style option list.
|
1039
|
+
# `nlopts`
|
1040
|
+
# : Negated long style options list.
|
1041
|
+
#
|
1042
|
+
#
|
1043
|
+
def update: (untyped sw, untyped sopts, untyped lopts, ?untyped nsw, ?untyped nlopts) -> untyped
|
1044
|
+
end
|
1045
|
+
|
1046
|
+
# Raises when a switch with mandatory argument has no argument.
|
1047
|
+
class OptionParser::MissingArgument < OptionParser::ParseError
|
1048
|
+
end
|
1049
|
+
|
1050
|
+
OptionParser::MissingArgument::Reason: String
|
1051
|
+
|
1052
|
+
# Raises when there is an argument for a switch which takes no argument.
|
1053
|
+
class OptionParser::NeedlessArgument < OptionParser::ParseError
|
1054
|
+
end
|
1055
|
+
|
1056
|
+
OptionParser::NeedlessArgument::Reason: String
|
1057
|
+
|
1058
|
+
# Map from option/keyword string to object with completion.
|
1059
|
+
class OptionParser::OptionMap < Hash[untyped, untyped]
|
1060
|
+
include OptionParser::Completion
|
1061
|
+
end
|
1062
|
+
|
1063
|
+
# Base class of exceptions from OptionParser.
|
1064
|
+
class OptionParser::ParseError < RuntimeError
|
1065
|
+
def self.filter_backtrace: (untyped array) -> untyped
|
1066
|
+
|
1067
|
+
public
|
1068
|
+
|
1069
|
+
def additional: () -> untyped
|
1070
|
+
|
1071
|
+
def additional=: (untyped) -> untyped
|
1072
|
+
|
1073
|
+
def args: () -> untyped
|
1074
|
+
|
1075
|
+
def inspect: () -> untyped
|
1076
|
+
|
1077
|
+
# Default stringizing method to emit standard error message.
|
1078
|
+
#
|
1079
|
+
def message: () -> String
|
1080
|
+
|
1081
|
+
def reason: () -> untyped
|
1082
|
+
|
1083
|
+
def reason=: (untyped) -> untyped
|
1084
|
+
|
1085
|
+
# Pushes back erred argument(s) to `argv`.
|
1086
|
+
#
|
1087
|
+
def recover: (untyped argv) -> untyped
|
1088
|
+
|
1089
|
+
def set_backtrace: (untyped array) -> untyped
|
1090
|
+
|
1091
|
+
def set_option: (untyped opt, untyped eq) -> untyped
|
1092
|
+
|
1093
|
+
alias to_s message
|
1094
|
+
|
1095
|
+
private
|
1096
|
+
|
1097
|
+
def initialize: (*untyped args, ?additional: untyped) -> void
|
1098
|
+
end
|
1099
|
+
|
1100
|
+
# Reason which caused the error.
|
1101
|
+
OptionParser::ParseError::Reason: String
|
1102
|
+
|
1103
|
+
# Individual switch class. Not important to the user.
|
1104
|
+
#
|
1105
|
+
# Defined within Switch are several Switch-derived classes: NoArgument,
|
1106
|
+
# RequiredArgument, etc.
|
1107
|
+
class OptionParser::Switch
|
1108
|
+
# Guesses argument style from `arg`. Returns corresponding OptionParser::Switch
|
1109
|
+
# class (OptionalArgument, etc.).
|
1110
|
+
#
|
1111
|
+
def self.guess: (untyped arg) -> untyped
|
1112
|
+
|
1113
|
+
def self.incompatible_argument_styles: (untyped arg, untyped t) -> untyped
|
1114
|
+
|
1115
|
+
def self.pattern: () -> untyped
|
1116
|
+
|
1117
|
+
public
|
1118
|
+
|
1119
|
+
def add_banner: (untyped to) -> untyped
|
1120
|
+
|
1121
|
+
def arg: () -> untyped
|
1122
|
+
|
1123
|
+
def block: () -> untyped
|
1124
|
+
|
1125
|
+
def compsys: (untyped sdone, untyped ldone) -> untyped
|
1126
|
+
|
1127
|
+
def conv: () -> untyped
|
1128
|
+
|
1129
|
+
def desc: () -> untyped
|
1130
|
+
|
1131
|
+
def long: () -> untyped
|
1132
|
+
|
1133
|
+
def match_nonswitch?: (untyped str) -> untyped
|
1134
|
+
|
1135
|
+
def pattern: () -> untyped
|
1136
|
+
|
1137
|
+
def short: () -> untyped
|
1138
|
+
|
1139
|
+
# Produces the summary text. Each line of the summary is yielded to the block
|
1140
|
+
# (without newline).
|
1141
|
+
#
|
1142
|
+
# `sdone`
|
1143
|
+
# : Already summarized short style options keyed hash.
|
1144
|
+
# `ldone`
|
1145
|
+
# : Already summarized long style options keyed hash.
|
1146
|
+
# `width`
|
1147
|
+
# : Width of left side (option part). In other words, the right side
|
1148
|
+
# (description part) starts after `width` columns.
|
1149
|
+
# `max`
|
1150
|
+
# : Maximum width of left side -> the options are filled within `max` columns.
|
1151
|
+
# `indent`
|
1152
|
+
# : Prefix string indents all summarized lines.
|
1153
|
+
#
|
1154
|
+
#
|
1155
|
+
def summarize: (?untyped sdone, ?untyped ldone, ?untyped width, ?untyped max, ?untyped indent) -> untyped
|
1156
|
+
|
1157
|
+
# Main name of the switch.
|
1158
|
+
#
|
1159
|
+
def switch_name: () -> untyped
|
1160
|
+
|
1161
|
+
private
|
1162
|
+
|
1163
|
+
# Parses argument, converts and returns `arg`, `block` and result of conversion.
|
1164
|
+
# Yields at semi-error condition instead of raising an exception.
|
1165
|
+
#
|
1166
|
+
def conv_arg: (untyped arg, ?untyped val) -> untyped
|
1167
|
+
|
1168
|
+
def initialize: (?untyped pattern, ?untyped conv, ?untyped short, ?untyped long, ?untyped arg, ?untyped desc, ?untyped block) { (*untyped) -> untyped } -> void
|
1169
|
+
|
1170
|
+
# Parses `arg` and returns rest of `arg` and matched portion to the argument
|
1171
|
+
# pattern. Yields when the pattern doesn't match substring.
|
1172
|
+
#
|
1173
|
+
def parse_arg: (untyped arg) -> untyped
|
1174
|
+
end
|
1175
|
+
|
1176
|
+
# Switch that takes no arguments.
|
1177
|
+
class OptionParser::Switch::NoArgument < OptionParser::Switch
|
1178
|
+
def self.incompatible_argument_styles: (*untyped) -> untyped
|
1179
|
+
|
1180
|
+
def self.pattern: () -> untyped
|
1181
|
+
|
1182
|
+
public
|
1183
|
+
|
1184
|
+
# Raises an exception if any arguments given.
|
1185
|
+
#
|
1186
|
+
def parse: (untyped arg, untyped argv) -> untyped
|
1187
|
+
end
|
1188
|
+
|
1189
|
+
# Switch that can omit argument.
|
1190
|
+
class OptionParser::Switch::OptionalArgument < OptionParser::Switch
|
1191
|
+
public
|
1192
|
+
|
1193
|
+
# Parses argument if given, or uses default value.
|
1194
|
+
#
|
1195
|
+
def parse: (untyped arg, untyped argv) { (*untyped) -> untyped } -> untyped
|
1196
|
+
end
|
1197
|
+
|
1198
|
+
# Switch that takes an argument, which does not begin with '-'.
|
1199
|
+
class OptionParser::Switch::PlacedArgument < OptionParser::Switch
|
1200
|
+
public
|
1201
|
+
|
1202
|
+
# Returns nil if argument is not present or begins with '-'.
|
1203
|
+
#
|
1204
|
+
def parse: (untyped arg, untyped argv) { (*untyped) -> untyped } -> untyped
|
1205
|
+
end
|
1206
|
+
|
1207
|
+
# Switch that takes an argument.
|
1208
|
+
class OptionParser::Switch::RequiredArgument < OptionParser::Switch
|
1209
|
+
public
|
1210
|
+
|
1211
|
+
# Raises an exception if argument is not present.
|
1212
|
+
#
|
1213
|
+
def parse: (untyped arg, untyped argv) -> untyped
|
1214
|
+
end
|