Skip to content

Commit d55d928

Browse files
BurdetteLamarnobu
authored andcommitted
Make use of option_params.rdoc
1 parent 5618eeb commit d55d928

File tree

4 files changed

+28
-67
lines changed

4 files changed

+28
-67
lines changed

doc/creates_option.rdoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Creates an option from the given parameters +params+.
2+
See {Parameters for New Options}[doc/option_params/option_params_rdoc.html].
3+
4+
The block, if given, is the handler for the created option.
5+
When the option is encountered during command-line parsing,
6+
the block is called with the argument given for the option, if any.
7+
See {Option Handlers}[doc/option_params/option_params_rdoc.html#label-Option+Handlers].

doc/option_params/option_params.rdoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Contents:
5555
- {Array}[#label-Array]
5656
- {Regexp}[#label-Regexp]
5757
- {Descriptions}[#label-Descriptions]
58-
- {Handlers}[#label-Handlers]
58+
- {Option Handlers}[#label-Option+Handlers]
5959
- {Handler Blocks}[#label-Handler+Blocks]
6060
- {Handler Procs}[#label-Handler+Procs]
6161
- {Handler Methods}[#label-Handler+Methods]
@@ -759,7 +759,7 @@ Executions:
759759
$ ruby descriptions.rb --xxx
760760
["--xxx", true]
761761

762-
=== Handlers
762+
=== Option Handlers
763763

764764
The handler for an option is an executable that will be called
765765
when the option is encountered. The handler may be:

lib/optparse.rb

Lines changed: 17 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,14 @@
240240
#
241241
# require 'optparse'
242242
#
243-
# params = {}
243+
# options = {}
244244
# OptionParser.new do |parser|
245245
# parser.on('-a')
246246
# parser.on('-b NUM', Integer)
247247
# parser.on('-v', '--verbose')
248-
# end.parse!(into: params)
248+
# end.parse!(into: options)
249249
#
250-
# p params
250+
# p options
251251
#
252252
# Used:
253253
#
@@ -1314,64 +1314,7 @@ def notwice(obj, prv, msg)
13141314
# :call-seq:
13151315
# make_switch(params, block = nil)
13161316
#
1317-
# Creates an OptionParser::Switch from the parameters. The parsed argument
1318-
# value is passed to the given block, where it can be processed.
1319-
#
1320-
# See at the beginning of OptionParser for some full examples.
1321-
#
1322-
# +params+ can include the following elements:
1323-
#
1324-
# [Argument style:]
1325-
# One of the following:
1326-
# :NONE, :REQUIRED, :OPTIONAL
1327-
#
1328-
# [Argument pattern:]
1329-
# Acceptable option argument format, must be pre-defined with
1330-
# OptionParser.accept or OptionParser#accept, or Regexp. This can appear
1331-
# once or assigned as String if not present, otherwise causes an
1332-
# ArgumentError. Examples:
1333-
# Float, Time, Array
1334-
#
1335-
# [Possible argument values:]
1336-
# Hash or Array.
1337-
# [:text, :binary, :auto]
1338-
# %w[iso-2022-jp shift_jis euc-jp utf8 binary]
1339-
# { "jis" => "iso-2022-jp", "sjis" => "shift_jis" }
1340-
#
1341-
# [Long style switch:]
1342-
# Specifies a long style switch which takes a mandatory, optional or no
1343-
# argument. It's a string of the following form:
1344-
# "--switch=MANDATORY" or "--switch MANDATORY"
1345-
# "--switch[=OPTIONAL]"
1346-
# "--switch"
1347-
#
1348-
# [Short style switch:]
1349-
# Specifies short style switch which takes a mandatory, optional or no
1350-
# argument. It's a string of the following form:
1351-
# "-xMANDATORY"
1352-
# "-x[OPTIONAL]"
1353-
# "-x"
1354-
# There is also a special form which matches character range (not full
1355-
# set of regular expression):
1356-
# "-[a-z]MANDATORY"
1357-
# "-[a-z][OPTIONAL]"
1358-
# "-[a-z]"
1359-
#
1360-
# [Argument style and description:]
1361-
# Instead of specifying mandatory or optional arguments directly in the
1362-
# switch parameter, this separate parameter can be used.
1363-
# "=MANDATORY"
1364-
# "=[OPTIONAL]"
1365-
#
1366-
# [Description:]
1367-
# Description string for the option.
1368-
# "Run verbosely"
1369-
# If you give multiple description strings, each string will be printed
1370-
# line by line.
1371-
#
1372-
# [Handler:]
1373-
# Handler for the parsed argument value. Either give a block or pass a
1374-
# Proc or Method as an argument.
1317+
# :include: ../doc/creates_option.rdoc
13751318
#
13761319
def make_switch(opts, block = nil)
13771320
short, long, nolong, style, pattern, conv, not_pattern, not_conv, not_style = [], [], []
@@ -1509,6 +1452,8 @@ def make_switch(opts, block = nil)
15091452
# :call-seq:
15101453
# define(*params, &block)
15111454
#
1455+
# :include: ../doc/creates_option.rdoc
1456+
#
15121457
def define(*opts, &block)
15131458
top.append(*(sw = make_switch(opts, block)))
15141459
sw[0]
@@ -1517,8 +1462,7 @@ def define(*opts, &block)
15171462
# :call-seq:
15181463
# on(*params, &block)
15191464
#
1520-
# Add option switch and handler. See #make_switch for an explanation of
1521-
# parameters.
1465+
# :include: ../doc/creates_option.rdoc
15221466
#
15231467
def on(*opts, &block)
15241468
define(*opts, &block)
@@ -1529,6 +1473,8 @@ def on(*opts, &block)
15291473
# :call-seq:
15301474
# define_head(*params, &block)
15311475
#
1476+
# :include: ../doc/creates_option.rdoc
1477+
#
15321478
def define_head(*opts, &block)
15331479
top.prepend(*(sw = make_switch(opts, block)))
15341480
sw[0]
@@ -1537,7 +1483,9 @@ def define_head(*opts, &block)
15371483
# :call-seq:
15381484
# on_head(*params, &block)
15391485
#
1540-
# Add option switch like with #on, but at head of summary.
1486+
# :include: ../doc/creates_option.rdoc
1487+
#
1488+
# The new option is added at the head of the summary.
15411489
#
15421490
def on_head(*opts, &block)
15431491
define_head(*opts, &block)
@@ -1548,6 +1496,8 @@ def on_head(*opts, &block)
15481496
# :call-seq:
15491497
# define_tail(*params, &block)
15501498
#
1499+
# :include: ../doc/creates_option.rdoc
1500+
#
15511501
def define_tail(*opts, &block)
15521502
base.append(*(sw = make_switch(opts, block)))
15531503
sw[0]
@@ -1557,7 +1507,9 @@ def define_tail(*opts, &block)
15571507
# :call-seq:
15581508
# on_tail(*params, &block)
15591509
#
1560-
# Add option switch like with #on, but at tail of summary.
1510+
# :include: ../doc/creates_option.rdoc
1511+
#
1512+
# The new option is added at the tail of the summary.
15611513
#
15621514
def on_tail(*opts, &block)
15631515
define_tail(*opts, &block)

lib/optparse/kwargs.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ class OptionParser
55
# :call-seq:
66
# define_by_keywords(options, method, **params)
77
#
8+
# :include: ../../doc/creates_option.rdoc
9+
#
810
def define_by_keywords(options, meth, **opts)
911
meth.parameters.each do |type, name|
1012
case type

0 commit comments

Comments
 (0)