Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/optparse/option_params.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Contents:
- {Long Names with Optional Arguments}[#label-Long+Names+with+Optional+Arguments]
- {Long Names with Negation}[#label-Long+Names+with+Negation]
- {Mixed Names}[#label-Mixed+Names]
- {Argument Styles}[#label-Argument+Styles]
- {Argument Strings}[#label-Argument+Strings]
- {Argument Values}[#label-Argument+Values]
- {Explicit Argument Values}[#label-Explicit+Argument+Values]
- {Explicit Values in Array}[#label-Explicit+Values+in+Array]
Expand Down
9 changes: 9 additions & 0 deletions doc/optparse/ruby/argument_abbreviation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'optparse'
parser = OptionParser.new
parser.on('-x', '--xxx=VALUE', %w[ABC def], 'Argument abbreviations') do |value|
p ['--xxx', value]
end
parser.on('-y', '--yyy=VALUE', {"abc"=>"XYZ", def: "FOO"}, 'Argument abbreviations') do |value|
p ['--yyy', value]
end
parser.parse!
23 changes: 23 additions & 0 deletions doc/optparse/tutorial.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,29 @@ Executions:

Omitting an optional argument does not raise an error.

==== Argument Abbreviations

Specify an argument list as an Array or a Hash.

:include: ruby/argument_abbreviation.rb

When an argument is abbreviated, the expanded argument yielded.

Executions:

$ ruby argument_abbreviation.rb --help
Usage: argument_abbreviation [options]
Usage: argument_abbreviation [options]
-x, --xxx=VALUE Argument abbreviations
-y, --yyy=VALUE Argument abbreviations
$ ruby argument_abbreviation.rb --xxx A
["--xxx", "ABC"]
$ ruby argument_abbreviation.rb --xxx c
argument_abbreviation.rb:9:in `<main>': invalid argument: --xxx c (OptionParser::InvalidArgument)
$ ruby argument_abbreviation.rb --yyy a --yyy d
["--yyy", "XYZ"]
["--yyy", "FOO"]

=== Argument Values

Permissible argument values may be restricted
Expand Down