diff options
author | Burdette Lamar <[email protected]> | 2021-04-22 07:27:06 -0500 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2021-07-28 20:13:39 +0900 |
commit | 27679b349e453b5ab1ce31472389bcb7ce550e4e () | |
tree | 50893f3ef721e47402f7265c5be7f45d3f00e3e5 | |
parent | a10db32003320a81c32a3733d9d97ba6e3614efa (diff) |
[ruby/optparse] More on tutorial (https://.com/ruby/optparse/pull/23)
- Removed a largish block of repeated text. - Added sections "Top List and Base List" and "Methods for Defining Options" (on, define, etc.). - Linked from class OptionParser doc to the tutorial. https://.com/ruby/optparse/commit/7f3195b9db
-rw-r--r-- | doc/optparse/ruby/basic.rb | 5 | ||||
-rw-r--r-- | doc/optparse/tutorial.rdoc | 79 | ||||
-rw-r--r-- | lib/optparse.rb | 10 |
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" |