mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* sample/optparse/opttest.rb: added.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5074 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
87762adcb0
commit
0f54ad5f6c
9 changed files with 130 additions and 34 deletions
|
@ -1,3 +1,7 @@
|
|||
Mon Dec 1 17:14:34 2003 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
|
||||
|
||||
* sample/optparse/opttest.rb: added.
|
||||
|
||||
Mon Dec 1 16:10:52 2003 Dave Thomas <dave@pragprog.com>
|
||||
|
||||
* lib/rdoc/rdoc.rb: (etc) initial merge into main tree.
|
||||
|
|
37
MANIFEST
37
MANIFEST
|
@ -83,6 +83,7 @@ bcc32/mkexports.rb
|
|||
bcc32/setup.mak
|
||||
bin/erb
|
||||
bin/irb
|
||||
bin/rdoc
|
||||
cygwin/GNUmakefile.in
|
||||
djgpp/GNUmakefile.in
|
||||
djgpp/README.djgpp
|
||||
|
@ -219,6 +220,40 @@ lib/profiler.rb
|
|||
lib/pstore.rb
|
||||
lib/racc/parser.rb
|
||||
lib/rational.rb
|
||||
lib/rdoc/README
|
||||
lib/rdoc/code_objects.rb
|
||||
lib/rdoc/diagram.rb
|
||||
lib/rdoc/options.rb
|
||||
lib/rdoc/rdoc.rb
|
||||
lib/rdoc/template.rb
|
||||
lib/rdoc/tokenstream.rb
|
||||
lib/rdoc/generators/chm_generator.rb
|
||||
lib/rdoc/generators/html_generator.rb
|
||||
lib/rdoc/generators/xml_generator.rb
|
||||
lib/rdoc/generators/template/chm/chm.rb
|
||||
lib/rdoc/generators/template/html/css2.rb
|
||||
lib/rdoc/generators/template/html/hefss.rb
|
||||
lib/rdoc/generators/template/html/html.rb
|
||||
lib/rdoc/generators/template/html/kilmer.rb
|
||||
lib/rdoc/generators/template/xml/rdf.rb
|
||||
lib/rdoc/generators/template/xml/xml.rb
|
||||
lib/rdoc/markup/sample/rdoc2latex.rb
|
||||
lib/rdoc/markup/sample/sample.rb
|
||||
lib/rdoc/markup/simple_markup.rb
|
||||
lib/rdoc/markup/simple_markup/fragments.rb
|
||||
lib/rdoc/markup/simple_markup/inline.rb
|
||||
lib/rdoc/markup/simple_markup/lines.rb
|
||||
lib/rdoc/markup/simple_markup/preprocess.rb
|
||||
lib/rdoc/markup/simple_markup/to_html.rb
|
||||
lib/rdoc/markup/simple_markup/to_latex.rb
|
||||
lib/rdoc/markup/test/AllTests.rb
|
||||
lib/rdoc/markup/test/TestInline.rb
|
||||
lib/rdoc/markup/test/TestParse.rb
|
||||
lib/rdoc/parsers/parse_c.rb
|
||||
lib/rdoc/parsers/parse_f95.rb
|
||||
lib/rdoc/parsers/parse_rb.rb
|
||||
lib/rdoc/parsers/parse_simple.rb
|
||||
lib/rdoc/parsers/parserfactory.rb
|
||||
lib/readbytes.rb
|
||||
lib/resolv-replace.rb
|
||||
lib/resolv.rb
|
||||
|
@ -561,6 +596,7 @@ sample/openssl/gen_csr.rb
|
|||
sample/openssl/smime_read.rb
|
||||
sample/openssl/smime_write.rb
|
||||
sample/openssl/wget.rb
|
||||
sample/optparse/opttest.rb
|
||||
sample/philos.rb
|
||||
sample/pi.rb
|
||||
sample/rcs.awk
|
||||
|
@ -745,6 +781,7 @@ test/wsdl/raa/RAAService.rb
|
|||
test/wsdl/raa/raa.wsdl
|
||||
test/wsdl/raa/test_raa.rb
|
||||
test/wsdl/test_emptycomplextype.rb
|
||||
test/wsdl/test_fault.rb
|
||||
test/xsd/noencoding.xml
|
||||
test/xsd/test_noencoding.rb
|
||||
test/xsd/test_xmlschemaparser.rb
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
MANIFEST
|
||||
depend
|
||||
MANIFEST
|
||||
Win32API.c
|
||||
extconf.rb
|
||||
getch.rb
|
||||
|
|
|
@ -7,38 +7,5 @@ digest.txt.ja
|
|||
extconf.rb
|
||||
lib/md5.rb
|
||||
lib/sha1.rb
|
||||
md5/MANIFEST
|
||||
md5/extconf.rb
|
||||
md5/md5.c
|
||||
md5/md5.h
|
||||
md5/md5init.c
|
||||
md5/md5ossl.c
|
||||
md5/md5ossl.h
|
||||
md5/depend
|
||||
rmd160/MANIFEST
|
||||
rmd160/extconf.rb
|
||||
rmd160/rmd160.c
|
||||
rmd160/rmd160.h
|
||||
rmd160/rmd160hl.c
|
||||
rmd160/rmd160init.c
|
||||
rmd160/rmd160ossl.c
|
||||
rmd160/rmd160ossl.h
|
||||
rmd160/depend
|
||||
sha1/MANIFEST
|
||||
sha1/extconf.rb
|
||||
sha1/sha1.c
|
||||
sha1/sha1.h
|
||||
sha1/sha1hl.c
|
||||
sha1/sha1init.c
|
||||
sha1/sha1ossl.c
|
||||
sha1/sha1ossl.h
|
||||
sha1/depend
|
||||
sha2/MANIFEST
|
||||
sha2/extconf.rb
|
||||
sha2/sha2.c
|
||||
sha2/sha2.h
|
||||
sha2/sha2hl.c
|
||||
sha2/sha2init.c
|
||||
sha2/depend
|
||||
test.sh
|
||||
depend
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
MANIFEST
|
||||
extconf.rb
|
||||
md5.c
|
||||
md5.h
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
MANIFEST
|
||||
extconf.rb
|
||||
rmd160.c
|
||||
rmd160.h
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
MANIFEST
|
||||
extconf.rb
|
||||
sha1.c
|
||||
sha1.h
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
MANIFEST
|
||||
extconf.rb
|
||||
sha2.c
|
||||
sha2.h
|
||||
|
|
85
sample/optparse/opttest.rb
Normal file
85
sample/optparse/opttest.rb
Normal file
|
@ -0,0 +1,85 @@
|
|||
#!/usr/bin/ruby -I.
|
||||
|
||||
require 'optparse'
|
||||
require 'optparse/time'
|
||||
require 'pp'
|
||||
|
||||
# keywords
|
||||
CODES = %w[iso-2022-jp shift_jis euc-jp utf8 binary]
|
||||
CODE_ALIASES = {"jis" => "iso-2022-jp", "sjis" => "shift_jis"}
|
||||
POSSIBLE_CODES = "(#{(CODES+CODE_ALIASES.keys).join(',')})"
|
||||
|
||||
ARGV.options do
|
||||
|opts|
|
||||
opts.banner << " argv..."
|
||||
|
||||
# separater
|
||||
opts.on_tail
|
||||
opts.on_tail("common options:")
|
||||
|
||||
# no argument, shows at tail
|
||||
opts.on_tail("--help", "show this message") {puts opts; exit}
|
||||
|
||||
# mandatory argument
|
||||
opts.on("-r", "--require=LIBRARY", String,
|
||||
"require the LIBRARY, before",
|
||||
"executing your script") {|@library|}
|
||||
|
||||
# optional argument
|
||||
opts.on("-i", "--inplace=[EXTENSION]",
|
||||
"edit ARGV files in place", # multiline description
|
||||
"(make backup if EXTENSION supplied)") {|@inplace| @inplace ||= ''}
|
||||
|
||||
opts.on("-N=[NUM]", Integer) {|@number|}
|
||||
|
||||
# additional class
|
||||
opts.on("-t", "--[no-]time[=TIME]", Time, "it's the time") {|@time|}
|
||||
|
||||
# limit argument syntax
|
||||
opts.on("-[0-7]", "-F", "--irs=[OCTAL]", OptionParser::OctalInteger,
|
||||
"specify record separator", "(\\0, if no argument)") {|@irs|}
|
||||
|
||||
# boolean switch(default true)
|
||||
@exec = true
|
||||
opts.on("-n", "--no-exec[=FLAG]", TrueClass, "not really execute") {|@exec|}
|
||||
|
||||
# array
|
||||
opts.on("-a", "--list[=LIST,LIST]", Array, "list") {|@list|}
|
||||
|
||||
# fixed size array
|
||||
opts.on("--pair[=car,cdr]", Array, "pair") {|@x, @y|}
|
||||
|
||||
# keyword completion
|
||||
opts.on("--code=CODE", CODES, CODE_ALIASES, "select coding system",
|
||||
"("+CODES.join(",")+",", " "+CODE_ALIASES.keys.join(",")+")") {|@code|}
|
||||
|
||||
# optional argument with keyword completion
|
||||
opts.on("--type[=TYPE]", [:text, :binary], "select type(text, binary)") {|@type|}
|
||||
|
||||
# boolean switch with optional argument(default false)
|
||||
opts.on("-v", "--[no-]verbose=[FLAG]", "run verbosely") {|@verbose|}
|
||||
|
||||
# easy way, set local variable
|
||||
opts.on("-q", "--quit", "quit when ARGV is empty") {|@quit|}
|
||||
|
||||
# adding on the fly
|
||||
opts.on("--add=SWITCH=[ARG]", "add option on the fly", /\A(\w+)(?:=.+)?\Z/) do
|
||||
|opt, var|
|
||||
opts.on("--#{opt}", "added in runtime", &eval("proc {|@#{var}|}"))
|
||||
end
|
||||
|
||||
opts.on_head("specific options:")
|
||||
|
||||
# no argument
|
||||
opts.on_tail("--version", "show version") do
|
||||
puts OptionParser::Version.join('.')
|
||||
exit
|
||||
end
|
||||
opts.parse!
|
||||
end
|
||||
|
||||
pp self
|
||||
(print ARGV.options; exit) if @quit
|
||||
ARGV.options = nil # no more parse
|
||||
puts "ARGV = #{ARGV.join(' ')}" if !ARGV.empty?
|
||||
#opts.variable.each {|sym| puts "#{sym} = #{opts.send(sym).inspect}"}
|
Loading…
Add table
Add a link
Reference in a new issue