ruby-changes:33116
From: zzak <ko1@a...>
Date: Thu, 27 Feb 2014 18:01:47 +0900 (JST)
Subject: [ruby-changes:33116] zzak:r45195 (trunk): * lib/optparse.rb: [DOC] Add example of generating help with optparse.
zzak 2014-02-27 18:01:43 +0900 (Thu, 27 Feb 2014) New Revision: 45195 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45195 Log: * lib/optparse.rb: [DOC] Add example of generating help with optparse. Patch by @joelmccracken documenting-ruby/ruby#19 https://github.com/documenting-ruby/ruby/pull/19 Modified files: trunk/ChangeLog trunk/lib/optparse.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 45194) +++ ChangeLog (revision 45195) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Feb 27 17:59:01 2014 Zachary Scott <e@z...> + + * lib/optparse.rb: [DOC] Add example of generating help with optparse. + Patch by @joelmccracken documenting-ruby/ruby#19 + https://github.com/documenting-ruby/ruby/pull/19 + Thu Feb 27 12:10:09 2014 Nobuyoshi Nakada <nobu@r...> * numeric.c (ruby_num_interval_step_size): check signs and get rid Index: lib/optparse.rb =================================================================== --- lib/optparse.rb (revision 45194) +++ lib/optparse.rb (revision 45195) @@ -82,6 +82,43 @@ https://github.com/ruby/ruby/blob/trunk/lib/optparse.rb#L82 # p options # p ARGV # +# === Generating Help +# +# OptionParser can be used to automatically generate help for the commands you +# write: +# +# require 'optparse' +# +# Options = Struct.new(:name) +# +# class Parser +# def self.parse(options) +# args = Options.new("world") +# +# opt_parser = OptionParser.new do |opts| +# opts.banner = "Usage: example.rb [options]" +# +# opts.on("-nNAME", "--name=NAME", "Name to say hello to") do |n| +# args.name = n +# end +# +# opts.on("-h", "--help", "Prints this help") do +# puts opts +# exit +# end +# end +# +# opt_parser.parse!(options) +# return args +# end +# end +# options = Parser.parse %w[--help] +# +# #=> +# # Usage: example.rb [options] +# # -n, --name=NAME Name to say hello to +# # -h, --help Prints this help# +# # === Complete example # # The following example is a complete Ruby program. You can run it and see the -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/