Skip to content

Commit 667ab35

Browse files
committed
[DOC] Add missing secition
Fixes #51
1 parent 1c895ef commit 667ab35

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require 'optparse'
2+
parser = OptionParser.new
3+
parser.on('-x', '--xxx=VALUE', %w[ABC def], 'Argument abbreviations') do |value|
4+
p ['--xxx', value]
5+
end
6+
parser.on('-y', '--yyy=VALUE', {"abc"=>"XYZ", def: "FOO"}, 'Argument abbreviations') do |value|
7+
p ['--yyy', value]
8+
end
9+
parser.parse!

doc/optparse/tutorial.rdoc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,29 @@ Executions:
351351

352352
Omitting an optional argument does not raise an error.
353353

354+
==== Argument Abbreviations
355+
356+
Specify an argument list as an Array or a Hash.
357+
358+
:include: ruby/argument_abbreviation.rb
359+
360+
When an argument is abbreviated, the expanded argument yielded.
361+
362+
Executions:
363+
364+
$ ruby argument_abbreviation.rb --help
365+
Usage: argument_abbreviation [options]
366+
Usage: argument_abbreviation [options]
367+
-x, --xxx=VALUE Argument abbreviations
368+
-y, --yyy=VALUE Argument abbreviations
369+
$ ruby argument_abbreviation.rb --xxx A
370+
["--xxx", "ABC"]
371+
$ ruby argument_abbreviation.rb --xxx c
372+
argument_abbreviation.rb:9:in `<main>': invalid argument: --xxx c (OptionParser::InvalidArgument)
373+
$ ruby argument_abbreviation.rb --yyy a --yyy d
374+
["--yyy", "XYZ"]
375+
["--yyy", "FOO"]
376+
354377
=== Argument Values
355378

356379
Permissible argument values may be restricted

0 commit comments

Comments
 (0)