summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/optparse/ruby/basic.rb5
-rw-r--r--doc/optparse/tutorial.rdoc79
-rw-r--r--lib/optparse.rb10
3 files changed, 81 insertions, 13 deletions
@@ -12,5 +12,6 @@ end
parser.on('-z', 'Whether to Z') do |value|
p ['z', value]
end
-# Parse the command line.
-parser.parse!
@@ -27,10 +27,7 @@ With \OptionParser, you can define options so that for each option:
- The argument may be restricted to specified _forms_.
- The argument may be restricted to specified _values_.
-The class also has:
-
-- Method #summarize: returns a text summary of the options.
-- Method #help: displays automatically-generated help text.
=== Contents
@@ -57,6 +54,8 @@ The class also has:
- {Default Values for Options}[#label-Default+Values+for+Options]
- {Argument Converters}[#label-Argument+Converters]
- {Help}[#label-Help]
=== To Begin With
@@ -83,16 +82,29 @@ From these defined options, the parser automatically builds help text:
When an option is found during parsing,
the block defined for the option is called with the argument value.
Executions:
$ ruby basic.rb -x -z
["x", true]
["z", true]
$ ruby basic.rb -z -y -x
["z", true]
["y", true]
["x", true]
=== Defining Options
@@ -151,11 +163,6 @@ Multiple short names can "share" a hyphen:
["-1 or -%", true]
["-1 or -%", true]
-This is a good time to note that giving an undefined option raises an exception:
-
- $ ruby short_names.rb -z
- short_names.rb:9:in `<main>': invalid option: -z (OptionParser::InvalidOption)
-
==== Long Option Names
A long option name consists of two hyphens and a one or more characters
@@ -597,3 +604,57 @@ Execution:
-z, --zzz [ZZZ] Et magnis dis parturient montes, nascetur
ridiculus mus. Donec quam felis, ultricies
nec, pellentesque eu, pretium quis, sem.
@@ -48,6 +48,10 @@
#
# == OptionParser
#
# === Introduction
#
# OptionParser is a class for command-line option analysis. It is much more
@@ -415,8 +419,10 @@
#
# === Further documentation
#
-# The above examples should be enough to learn how to use this class. If you
-# have any questions, file a ticket at http://bugs.ruby-lang.org.
#
class OptionParser
OptionParser::Version = "0.1.1"