ruby_on_ruby 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.rvmrc +1 -0
- data/Gemfile +6 -0
- data/LICENSE +22 -0
- data/README.md +66 -0
- data/Rakefile +1 -0
- data/lib/ruby_on_ruby.rb +5 -0
- data/lib/ruby_on_ruby/console.rb +7 -0
- data/lib/ruby_on_ruby/context.rb +33 -0
- data/lib/ruby_on_ruby/file_loader.rb +31 -0
- data/lib/ruby_on_ruby/ruby_stream.rb +27 -0
- data/lib/ruby_on_ruby/version.rb +3 -0
- data/lib/rubyonruby.rb +1 -0
- data/ruby_in_ruby.gemspec +19 -0
- data/vendor/javascripts/emscripted-ruby/lib/.document +106 -0
- data/vendor/javascripts/emscripted-ruby/lib/English.rb +155 -0
- data/vendor/javascripts/emscripted-ruby/lib/Env.rb +18 -0
- data/vendor/javascripts/emscripted-ruby/lib/README +96 -0
- data/vendor/javascripts/emscripted-ruby/lib/abbrev.rb +103 -0
- data/vendor/javascripts/emscripted-ruby/lib/base64.rb +133 -0
- data/vendor/javascripts/emscripted-ruby/lib/benchmark.rb +572 -0
- data/vendor/javascripts/emscripted-ruby/lib/cgi-lib.rb +272 -0
- data/vendor/javascripts/emscripted-ruby/lib/cgi.rb +2308 -0
- data/vendor/javascripts/emscripted-ruby/lib/cgi/.document +2 -0
- data/vendor/javascripts/emscripted-ruby/lib/cgi/session.rb +498 -0
- data/vendor/javascripts/emscripted-ruby/lib/cgi/session/pstore.rb +111 -0
- data/vendor/javascripts/emscripted-ruby/lib/complex.rb +663 -0
- data/vendor/javascripts/emscripted-ruby/lib/csv.rb +992 -0
- data/vendor/javascripts/emscripted-ruby/lib/date.rb +1767 -0
- data/vendor/javascripts/emscripted-ruby/lib/date/format.rb +1190 -0
- data/vendor/javascripts/emscripted-ruby/lib/date2.rb +5 -0
- data/vendor/javascripts/emscripted-ruby/lib/debug.rb +947 -0
- data/vendor/javascripts/emscripted-ruby/lib/delegate.rb +337 -0
- data/vendor/javascripts/emscripted-ruby/lib/drb.rb +2 -0
- data/vendor/javascripts/emscripted-ruby/lib/drb/acl.rb +146 -0
- data/vendor/javascripts/emscripted-ruby/lib/drb/drb.rb +1782 -0
- data/vendor/javascripts/emscripted-ruby/lib/drb/eq.rb +16 -0
- data/vendor/javascripts/emscripted-ruby/lib/drb/extserv.rb +64 -0
- data/vendor/javascripts/emscripted-ruby/lib/drb/extservm.rb +89 -0
- data/vendor/javascripts/emscripted-ruby/lib/drb/gw.rb +122 -0
- data/vendor/javascripts/emscripted-ruby/lib/drb/invokemethod.rb +36 -0
- data/vendor/javascripts/emscripted-ruby/lib/drb/observer.rb +22 -0
- data/vendor/javascripts/emscripted-ruby/lib/drb/ssl.rb +190 -0
- data/vendor/javascripts/emscripted-ruby/lib/drb/timeridconv.rb +91 -0
- data/vendor/javascripts/emscripted-ruby/lib/drb/unix.rb +108 -0
- data/vendor/javascripts/emscripted-ruby/lib/e2mmap.rb +195 -0
- data/vendor/javascripts/emscripted-ruby/lib/erb.rb +880 -0
- data/vendor/javascripts/emscripted-ruby/lib/eregex.rb +37 -0
- data/vendor/javascripts/emscripted-ruby/lib/fileutils.rb +1591 -0
- data/vendor/javascripts/emscripted-ruby/lib/finalize.rb +193 -0
- data/vendor/javascripts/emscripted-ruby/lib/find.rb +79 -0
- data/vendor/javascripts/emscripted-ruby/lib/forwardable.rb +218 -0
- data/vendor/javascripts/emscripted-ruby/lib/ftools.rb +261 -0
- data/vendor/javascripts/emscripted-ruby/lib/generator.rb +418 -0
- data/vendor/javascripts/emscripted-ruby/lib/getoptlong.rb +621 -0
- data/vendor/javascripts/emscripted-ruby/lib/getopts.rb +127 -0
- data/vendor/javascripts/emscripted-ruby/lib/gserver.rb +253 -0
- data/vendor/javascripts/emscripted-ruby/lib/importenv.rb +33 -0
- data/vendor/javascripts/emscripted-ruby/lib/ipaddr.rb +814 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb.rb +346 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/cmd/chws.rb +33 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/cmd/fork.rb +39 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/cmd/help.rb +34 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/cmd/load.rb +67 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/cmd/nop.rb +39 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/cmd/pushws.rb +39 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/cmd/subirb.rb +43 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/completion.rb +205 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/context.rb +255 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/ext/change-ws.rb +62 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/ext/history.rb +110 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/ext/loader.rb +120 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/ext/math-mode.rb +37 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/ext/multi-irb.rb +241 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/ext/save-history.rb +85 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/ext/tracer.rb +61 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/ext/use-loader.rb +65 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/ext/workspaces.rb +56 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/extend-command.rb +264 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/frame.rb +67 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/help.rb +33 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/init.rb +259 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/input-method.rb +120 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/lc/error.rb +30 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/lc/help-message +35 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/lc/ja/error.rb +27 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/lc/ja/help-message +36 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/locale.rb +184 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/notifier.rb +145 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/output-method.rb +85 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/ruby-lex.rb +1149 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/ruby-token.rb +273 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/slex.rb +285 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/version.rb +16 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/workspace.rb +107 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/ws-for-case-2.rb +15 -0
- data/vendor/javascripts/emscripted-ruby/lib/irb/xmp.rb +86 -0
- data/vendor/javascripts/emscripted-ruby/lib/jcode.rb +220 -0
- data/vendor/javascripts/emscripted-ruby/lib/logger.rb +703 -0
- data/vendor/javascripts/emscripted-ruby/lib/mailread.rb +62 -0
- data/vendor/javascripts/emscripted-ruby/lib/mathn.rb +308 -0
- data/vendor/javascripts/emscripted-ruby/lib/matrix.rb +1278 -0
- data/vendor/javascripts/emscripted-ruby/lib/mkmf.rb +1811 -0
- data/vendor/javascripts/emscripted-ruby/lib/monitor.rb +352 -0
- data/vendor/javascripts/emscripted-ruby/lib/mutex_m.rb +122 -0
- data/vendor/javascripts/emscripted-ruby/lib/net/ftp.rb +927 -0
- data/vendor/javascripts/emscripted-ruby/lib/net/http.rb +2277 -0
- data/vendor/javascripts/emscripted-ruby/lib/net/https.rb +173 -0
- data/vendor/javascripts/emscripted-ruby/lib/net/imap.rb +3371 -0
- data/vendor/javascripts/emscripted-ruby/lib/net/pop.rb +999 -0
- data/vendor/javascripts/emscripted-ruby/lib/net/protocol.rb +392 -0
- data/vendor/javascripts/emscripted-ruby/lib/net/smtp.rb +1014 -0
- data/vendor/javascripts/emscripted-ruby/lib/net/telnet.rb +756 -0
- data/vendor/javascripts/emscripted-ruby/lib/observer.rb +192 -0
- data/vendor/javascripts/emscripted-ruby/lib/open-uri.rb +678 -0
- data/vendor/javascripts/emscripted-ruby/lib/open3.rb +101 -0
- data/vendor/javascripts/emscripted-ruby/lib/optparse.rb +1790 -0
- data/vendor/javascripts/emscripted-ruby/lib/optparse/date.rb +17 -0
- data/vendor/javascripts/emscripted-ruby/lib/optparse/shellwords.rb +6 -0
- data/vendor/javascripts/emscripted-ruby/lib/optparse/time.rb +10 -0
- data/vendor/javascripts/emscripted-ruby/lib/optparse/uri.rb +6 -0
- data/vendor/javascripts/emscripted-ruby/lib/optparse/version.rb +70 -0
- data/vendor/javascripts/emscripted-ruby/lib/ostruct.rb +146 -0
- data/vendor/javascripts/emscripted-ruby/lib/parsearg.rb +87 -0
- data/vendor/javascripts/emscripted-ruby/lib/parsedate.rb +53 -0
- data/vendor/javascripts/emscripted-ruby/lib/pathname.rb +1062 -0
- data/vendor/javascripts/emscripted-ruby/lib/ping.rb +64 -0
- data/vendor/javascripts/emscripted-ruby/lib/pp.rb +654 -0
- data/vendor/javascripts/emscripted-ruby/lib/prettyprint.rb +896 -0
- data/vendor/javascripts/emscripted-ruby/lib/profile.rb +6 -0
- data/vendor/javascripts/emscripted-ruby/lib/profiler.rb +59 -0
- data/vendor/javascripts/emscripted-ruby/lib/pstore.rb +395 -0
- data/vendor/javascripts/emscripted-ruby/lib/racc/parser.rb +442 -0
- data/vendor/javascripts/emscripted-ruby/lib/rational.rb +564 -0
- data/vendor/javascripts/emscripted-ruby/lib/readbytes.rb +41 -0
- data/vendor/javascripts/emscripted-ruby/lib/resolv-replace.rb +62 -0
- data/vendor/javascripts/emscripted-ruby/lib/resolv.rb +2210 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/attlistdecl.rb +62 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/attribute.rb +185 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/cdata.rb +67 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/child.rb +96 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/comment.rb +80 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/doctype.rb +271 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/document.rb +208 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/dtd/attlistdecl.rb +10 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/dtd/dtd.rb +51 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/dtd/elementdecl.rb +17 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/dtd/entitydecl.rb +56 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/dtd/notationdecl.rb +39 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/element.rb +1227 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/encoding.rb +71 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/CP-1252.rb +103 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/EUC-JP.rb +35 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/ICONV.rb +22 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/ISO-8859-1.rb +7 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/ISO-8859-15.rb +72 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/SHIFT-JIS.rb +37 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/SHIFT_JIS.rb +1 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/UNILE.rb +34 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/US-ASCII.rb +30 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/UTF-16.rb +35 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/UTF-8.rb +18 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/entity.rb +165 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/formatters/default.rb +109 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/formatters/pretty.rb +137 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/formatters/transitive.rb +56 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/functions.rb +382 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/instruction.rb +70 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/light/node.rb +196 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/namespace.rb +47 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/node.rb +75 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/output.rb +24 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/parent.rb +166 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/parseexception.rb +51 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/parsers/baseparser.rb +503 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/parsers/lightparser.rb +60 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/parsers/pullparser.rb +196 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/parsers/sax2parser.rb +238 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/parsers/streamparser.rb +46 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/parsers/treeparser.rb +97 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/parsers/ultralightparser.rb +56 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/parsers/xpathparser.rb +698 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/quickpath.rb +266 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/rexml.rb +32 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/sax2listener.rb +97 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/source.rb +251 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/streamlistener.rb +92 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/syncenumerator.rb +33 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/text.rb +344 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/undefinednamespaceexception.rb +8 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/validation/relaxng.rb +559 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/validation/validation.rb +155 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/validation/validationexception.rb +9 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/xmldecl.rb +119 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/xmltokens.rb +18 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/xpath.rb +66 -0
- data/vendor/javascripts/emscripted-ruby/lib/rexml/xpath_parser.rb +792 -0
- data/vendor/javascripts/emscripted-ruby/lib/rinda/rinda.rb +283 -0
- data/vendor/javascripts/emscripted-ruby/lib/rinda/ring.rb +271 -0
- data/vendor/javascripts/emscripted-ruby/lib/rinda/tuplespace.rb +642 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss.rb +19 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/0.9.rb +428 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/1.0.rb +452 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/2.0.rb +111 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/atom.rb +749 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/content.rb +31 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/content/1.0.rb +10 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/content/2.0.rb +12 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/converter.rb +162 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/dublincore.rb +161 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/dublincore/1.0.rb +13 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/dublincore/2.0.rb +13 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/dublincore/atom.rb +17 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/image.rb +193 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/itunes.rb +410 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/maker.rb +44 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/maker/0.9.rb +467 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/maker/1.0.rb +434 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/maker/2.0.rb +223 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/maker/atom.rb +172 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/maker/base.rb +868 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/maker/content.rb +21 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/maker/dublincore.rb +124 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/maker/entry.rb +163 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/maker/feed.rb +429 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/maker/image.rb +111 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/maker/itunes.rb +242 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/maker/slash.rb +33 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/maker/syndication.rb +18 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/maker/taxonomy.rb +118 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/maker/trackback.rb +61 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/parser.rb +541 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/rexmlparser.rb +54 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/rss.rb +1312 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/slash.rb +49 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/syndication.rb +67 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/taxonomy.rb +145 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/trackback.rb +288 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/utils.rb +111 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/xml-stylesheet.rb +105 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/xml.rb +71 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/xmlparser.rb +93 -0
- data/vendor/javascripts/emscripted-ruby/lib/rss/xmlscanner.rb +121 -0
- data/vendor/javascripts/emscripted-ruby/lib/rubyunit.rb +6 -0
- data/vendor/javascripts/emscripted-ruby/lib/runit/assert.rb +73 -0
- data/vendor/javascripts/emscripted-ruby/lib/runit/cui/testrunner.rb +51 -0
- data/vendor/javascripts/emscripted-ruby/lib/runit/error.rb +9 -0
- data/vendor/javascripts/emscripted-ruby/lib/runit/testcase.rb +45 -0
- data/vendor/javascripts/emscripted-ruby/lib/runit/testresult.rb +44 -0
- data/vendor/javascripts/emscripted-ruby/lib/runit/testsuite.rb +26 -0
- data/vendor/javascripts/emscripted-ruby/lib/runit/topublic.rb +8 -0
- data/vendor/javascripts/emscripted-ruby/lib/scanf.rb +702 -0
- data/vendor/javascripts/emscripted-ruby/lib/securerandom.rb +137 -0
- data/vendor/javascripts/emscripted-ruby/lib/set.rb +1233 -0
- data/vendor/javascripts/emscripted-ruby/lib/shell.rb +269 -0
- data/vendor/javascripts/emscripted-ruby/lib/shell/builtin-command.rb +154 -0
- data/vendor/javascripts/emscripted-ruby/lib/shell/command-processor.rb +592 -0
- data/vendor/javascripts/emscripted-ruby/lib/shell/error.rb +26 -0
- data/vendor/javascripts/emscripted-ruby/lib/shell/filter.rb +110 -0
- data/vendor/javascripts/emscripted-ruby/lib/shell/process-controller.rb +260 -0
- data/vendor/javascripts/emscripted-ruby/lib/shell/system-command.rb +168 -0
- data/vendor/javascripts/emscripted-ruby/lib/shell/version.rb +16 -0
- data/vendor/javascripts/emscripted-ruby/lib/shellwords.rb +172 -0
- data/vendor/javascripts/emscripted-ruby/lib/singleton.rb +360 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/attachment.rb +107 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/baseData.rb +942 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/element.rb +258 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/encodingstyle/aspDotNetHandler.rb +213 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/encodingstyle/handler.rb +100 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/encodingstyle/literalHandler.rb +226 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/encodingstyle/soapHandler.rb +582 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/generator.rb +268 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/header/handler.rb +57 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/header/handlerset.rb +70 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/header/simplehandler.rb +44 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/httpconfigloader.rb +119 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/mapping.rb +10 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/mapping/factory.rb +355 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/mapping/mapping.rb +381 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/mapping/registry.rb +541 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/mapping/rubytypeFactory.rb +475 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/mapping/typeMap.rb +50 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/mapping/wsdlencodedregistry.rb +280 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/mapping/wsdlliteralregistry.rb +418 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/marshal.rb +59 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/mimemessage.rb +240 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/netHttpClient.rb +190 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/parser.rb +251 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/processor.rb +66 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/property.rb +333 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/cgistub.rb +206 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/driver.rb +254 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/element.rb +325 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/httpserver.rb +129 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/proxy.rb +497 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/router.rb +594 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/rpc.rb +25 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/soaplet.rb +162 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/standaloneServer.rb +43 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/soap.rb +140 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/streamHandler.rb +229 -0
- data/vendor/javascripts/emscripted-ruby/lib/soap/wsdlDriver.rb +575 -0
- data/vendor/javascripts/emscripted-ruby/lib/sync.rb +311 -0
- data/vendor/javascripts/emscripted-ruby/lib/tempfile.rb +209 -0
- data/vendor/javascripts/emscripted-ruby/lib/test/unit.rb +280 -0
- data/vendor/javascripts/emscripted-ruby/lib/test/unit/assertionfailederror.rb +14 -0
- data/vendor/javascripts/emscripted-ruby/lib/test/unit/assertions.rb +622 -0
- data/vendor/javascripts/emscripted-ruby/lib/test/unit/autorunner.rb +220 -0
- data/vendor/javascripts/emscripted-ruby/lib/test/unit/collector.rb +43 -0
- data/vendor/javascripts/emscripted-ruby/lib/test/unit/collector/dir.rb +107 -0
- data/vendor/javascripts/emscripted-ruby/lib/test/unit/collector/objectspace.rb +34 -0
- data/vendor/javascripts/emscripted-ruby/lib/test/unit/error.rb +56 -0
- data/vendor/javascripts/emscripted-ruby/lib/test/unit/failure.rb +51 -0
- data/vendor/javascripts/emscripted-ruby/lib/test/unit/testcase.rb +160 -0
- data/vendor/javascripts/emscripted-ruby/lib/test/unit/testresult.rb +80 -0
- data/vendor/javascripts/emscripted-ruby/lib/test/unit/testsuite.rb +76 -0
- data/vendor/javascripts/emscripted-ruby/lib/test/unit/ui/console/testrunner.rb +127 -0
- data/vendor/javascripts/emscripted-ruby/lib/test/unit/ui/fox/testrunner.rb +268 -0
- data/vendor/javascripts/emscripted-ruby/lib/test/unit/ui/gtk/testrunner.rb +416 -0
- data/vendor/javascripts/emscripted-ruby/lib/test/unit/ui/gtk2/testrunner.rb +465 -0
- data/vendor/javascripts/emscripted-ruby/lib/test/unit/ui/testrunnermediator.rb +68 -0
- data/vendor/javascripts/emscripted-ruby/lib/test/unit/ui/testrunnerutilities.rb +46 -0
- data/vendor/javascripts/emscripted-ruby/lib/test/unit/ui/tk/testrunner.rb +260 -0
- data/vendor/javascripts/emscripted-ruby/lib/test/unit/util/backtracefilter.rb +40 -0
- data/vendor/javascripts/emscripted-ruby/lib/test/unit/util/observable.rb +90 -0
- data/vendor/javascripts/emscripted-ruby/lib/test/unit/util/procwrapper.rb +48 -0
- data/vendor/javascripts/emscripted-ruby/lib/thread.rb +479 -0
- data/vendor/javascripts/emscripted-ruby/lib/thwait.rb +169 -0
- data/vendor/javascripts/emscripted-ruby/lib/time.rb +797 -0
- data/vendor/javascripts/emscripted-ruby/lib/timeout.rb +122 -0
- data/vendor/javascripts/emscripted-ruby/lib/tmpdir.rb +130 -0
- data/vendor/javascripts/emscripted-ruby/lib/tracer.rb +167 -0
- data/vendor/javascripts/emscripted-ruby/lib/tsort.rb +290 -0
- data/vendor/javascripts/emscripted-ruby/lib/un.rb +235 -0
- data/vendor/javascripts/emscripted-ruby/lib/uri.rb +29 -0
- data/vendor/javascripts/emscripted-ruby/lib/uri/common.rb +611 -0
- data/vendor/javascripts/emscripted-ruby/lib/uri/ftp.rb +198 -0
- data/vendor/javascripts/emscripted-ruby/lib/uri/generic.rb +1122 -0
- data/vendor/javascripts/emscripted-ruby/lib/uri/http.rb +100 -0
- data/vendor/javascripts/emscripted-ruby/lib/uri/https.rb +20 -0
- data/vendor/javascripts/emscripted-ruby/lib/uri/ldap.rb +190 -0
- data/vendor/javascripts/emscripted-ruby/lib/uri/ldaps.rb +12 -0
- data/vendor/javascripts/emscripted-ruby/lib/uri/mailto.rb +266 -0
- data/vendor/javascripts/emscripted-ruby/lib/weakref.rb +100 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick.rb +29 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/accesslog.rb +67 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/cgi.rb +257 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/compat.rb +15 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/config.rb +97 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/cookie.rb +110 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/htmlutils.rb +25 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/httpauth.rb +45 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/httpauth/authenticator.rb +79 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/httpauth/basicauth.rb +65 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/httpauth/digestauth.rb +343 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/httpauth/htdigest.rb +91 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/httpauth/htgroup.rb +61 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/httpauth/htpasswd.rb +83 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/httpauth/userdb.rb +29 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/httpproxy.rb +254 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/httprequest.rb +365 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/httpresponse.rb +327 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/https.rb +63 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/httpserver.rb +210 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/httpservlet.rb +22 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/httpservlet/abstract.rb +71 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/httpservlet/cgi_runner.rb +47 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/httpservlet/cgihandler.rb +108 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/httpservlet/erbhandler.rb +54 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/httpservlet/filehandler.rb +435 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/httpservlet/prochandler.rb +33 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/httpstatus.rb +126 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/httputils.rb +399 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/httpversion.rb +49 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/log.rb +88 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/server.rb +200 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/ssl.rb +126 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/utils.rb +100 -0
- data/vendor/javascripts/emscripted-ruby/lib/webrick/version.rb +13 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/binding.rb +65 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/data.rb +64 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/definitions.rb +250 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/documentation.rb +32 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/import.rb +80 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/importer.rb +38 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/info.rb +39 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/message.rb +54 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/operation.rb +130 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/operationBinding.rb +108 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/param.rb +85 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/parser.rb +163 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/part.rb +52 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/port.rb +84 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/portType.rb +73 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/service.rb +61 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/address.rb +40 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/binding.rb +49 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/body.rb +56 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/cgiStubCreator.rb +76 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/classDefCreator.rb +314 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/classDefCreatorSupport.rb +126 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/clientSkeltonCreator.rb +78 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/complexType.rb +161 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/data.rb +42 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/definitions.rb +149 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/driverCreator.rb +95 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/element.rb +28 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/fault.rb +56 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/header.rb +86 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/headerfault.rb +56 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/mappingRegistryCreator.rb +92 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/methodDefCreator.rb +228 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/operation.rb +122 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/servantSkeltonCreator.rb +67 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/standaloneServerStubCreator.rb +85 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/wsdl2ruby.rb +176 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/types.rb +43 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/wsdl.rb +23 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/all.rb +69 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/annotation.rb +34 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/any.rb +56 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/attribute.rb +127 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/choice.rb +69 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/complexContent.rb +92 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/complexType.rb +139 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/content.rb +96 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/data.rb +80 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/element.rb +154 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/enumeration.rb +36 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/import.rb +65 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/importer.rb +87 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/include.rb +54 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/length.rb +35 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/parser.rb +166 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/pattern.rb +36 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/schema.rb +143 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/sequence.rb +69 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/simpleContent.rb +65 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/simpleExtension.rb +54 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/simpleRestriction.rb +73 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/simpleType.rb +73 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/unique.rb +34 -0
- data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/xsd2ruby.rb +107 -0
- data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/.document +1 -0
- data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/README.txt +31 -0
- data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/base64.rb +81 -0
- data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/client.rb +624 -0
- data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/config.rb +40 -0
- data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/create.rb +290 -0
- data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/datetime.rb +142 -0
- data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/httpserver.rb +178 -0
- data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/marshal.rb +76 -0
- data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/parser.rb +813 -0
- data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/server.rb +780 -0
- data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/utils.rb +165 -0
- data/vendor/javascripts/emscripted-ruby/lib/xsd/charset.rb +187 -0
- data/vendor/javascripts/emscripted-ruby/lib/xsd/codegen.rb +12 -0
- data/vendor/javascripts/emscripted-ruby/lib/xsd/codegen/classdef.rb +203 -0
- data/vendor/javascripts/emscripted-ruby/lib/xsd/codegen/commentdef.rb +34 -0
- data/vendor/javascripts/emscripted-ruby/lib/xsd/codegen/gensupport.rb +166 -0
- data/vendor/javascripts/emscripted-ruby/lib/xsd/codegen/methoddef.rb +63 -0
- data/vendor/javascripts/emscripted-ruby/lib/xsd/codegen/moduledef.rb +191 -0
- data/vendor/javascripts/emscripted-ruby/lib/xsd/datatypes.rb +1269 -0
- data/vendor/javascripts/emscripted-ruby/lib/xsd/datatypes1999.rb +20 -0
- data/vendor/javascripts/emscripted-ruby/lib/xsd/iconvcharset.rb +33 -0
- data/vendor/javascripts/emscripted-ruby/lib/xsd/mapping.rb +42 -0
- data/vendor/javascripts/emscripted-ruby/lib/xsd/namedelements.rb +95 -0
- data/vendor/javascripts/emscripted-ruby/lib/xsd/ns.rb +140 -0
- data/vendor/javascripts/emscripted-ruby/lib/xsd/qname.rb +78 -0
- data/vendor/javascripts/emscripted-ruby/lib/xsd/xmlparser.rb +61 -0
- data/vendor/javascripts/emscripted-ruby/lib/xsd/xmlparser/parser.rb +96 -0
- data/vendor/javascripts/emscripted-ruby/lib/xsd/xmlparser/rexmlparser.rb +54 -0
- data/vendor/javascripts/emscripted-ruby/lib/xsd/xmlparser/xmlparser.rb +50 -0
- data/vendor/javascripts/emscripted-ruby/lib/xsd/xmlparser/xmlscanner.rb +147 -0
- data/vendor/javascripts/emscripted-ruby/lib/yaml.rb +440 -0
- data/vendor/javascripts/emscripted-ruby/lib/yaml/baseemitter.rb +247 -0
- data/vendor/javascripts/emscripted-ruby/lib/yaml/basenode.rb +216 -0
- data/vendor/javascripts/emscripted-ruby/lib/yaml/constants.rb +45 -0
- data/vendor/javascripts/emscripted-ruby/lib/yaml/dbm.rb +111 -0
- data/vendor/javascripts/emscripted-ruby/lib/yaml/encoding.rb +33 -0
- data/vendor/javascripts/emscripted-ruby/lib/yaml/error.rb +34 -0
- data/vendor/javascripts/emscripted-ruby/lib/yaml/loader.rb +14 -0
- data/vendor/javascripts/emscripted-ruby/lib/yaml/rubytypes.rb +408 -0
- data/vendor/javascripts/emscripted-ruby/lib/yaml/store.rb +43 -0
- data/vendor/javascripts/emscripted-ruby/lib/yaml/stream.rb +40 -0
- data/vendor/javascripts/emscripted-ruby/lib/yaml/stringio.rb +83 -0
- data/vendor/javascripts/emscripted-ruby/lib/yaml/syck.rb +19 -0
- data/vendor/javascripts/emscripted-ruby/lib/yaml/tag.rb +91 -0
- data/vendor/javascripts/emscripted-ruby/lib/yaml/types.rb +192 -0
- data/vendor/javascripts/emscripted-ruby/lib/yaml/yamlnode.rb +54 -0
- data/vendor/javascripts/emscripted-ruby/lib/yaml/ypath.rb +52 -0
- data/vendor/javascripts/emscripted-ruby/ruby.closure.js +7201 -0
- metadata +554 -0
@@ -0,0 +1,101 @@
|
|
1
|
+
#
|
2
|
+
# = open3.rb: Popen, but with stderr, too
|
3
|
+
#
|
4
|
+
# Author:: Yukihiro Matsumoto
|
5
|
+
# Documentation:: Konrad Meyer
|
6
|
+
#
|
7
|
+
# Open3 gives you access to stdin, stdout, and stderr when running other
|
8
|
+
# programs.
|
9
|
+
#
|
10
|
+
|
11
|
+
#
|
12
|
+
# Open3 grants you access to stdin, stdout, and stderr when running another
|
13
|
+
# program. Example:
|
14
|
+
#
|
15
|
+
# require "open3"
|
16
|
+
# include Open3
|
17
|
+
#
|
18
|
+
# stdin, stdout, stderr = popen3('nroff -man')
|
19
|
+
#
|
20
|
+
# Open3.popen3 can also take a block which will receive stdin, stdout and
|
21
|
+
# stderr as parameters. This ensures stdin, stdout and stderr are closed
|
22
|
+
# once the block exits. Example:
|
23
|
+
#
|
24
|
+
# require "open3"
|
25
|
+
#
|
26
|
+
# Open3.popen3('nroff -man') { |stdin, stdout, stderr| ... }
|
27
|
+
#
|
28
|
+
|
29
|
+
module Open3
|
30
|
+
#
|
31
|
+
# Open stdin, stdout, and stderr streams and start external executable.
|
32
|
+
# Non-block form:
|
33
|
+
#
|
34
|
+
# require 'open3'
|
35
|
+
#
|
36
|
+
# [stdin, stdout, stderr] = Open3.popen3(cmd)
|
37
|
+
#
|
38
|
+
# Block form:
|
39
|
+
#
|
40
|
+
# require 'open3'
|
41
|
+
#
|
42
|
+
# Open3.popen3(cmd) { |stdin, stdout, stderr| ... }
|
43
|
+
#
|
44
|
+
# The parameter +cmd+ is passed directly to Kernel#exec.
|
45
|
+
#
|
46
|
+
def popen3(*cmd)
|
47
|
+
pw = IO::pipe # pipe[0] for read, pipe[1] for write
|
48
|
+
pr = IO::pipe
|
49
|
+
pe = IO::pipe
|
50
|
+
|
51
|
+
pid = fork{
|
52
|
+
# child
|
53
|
+
fork{
|
54
|
+
# grandchild
|
55
|
+
pw[1].close
|
56
|
+
STDIN.reopen(pw[0])
|
57
|
+
pw[0].close
|
58
|
+
|
59
|
+
pr[0].close
|
60
|
+
STDOUT.reopen(pr[1])
|
61
|
+
pr[1].close
|
62
|
+
|
63
|
+
pe[0].close
|
64
|
+
STDERR.reopen(pe[1])
|
65
|
+
pe[1].close
|
66
|
+
|
67
|
+
exec(*cmd)
|
68
|
+
}
|
69
|
+
exit!(0)
|
70
|
+
}
|
71
|
+
|
72
|
+
pw[0].close
|
73
|
+
pr[1].close
|
74
|
+
pe[1].close
|
75
|
+
Process.waitpid(pid)
|
76
|
+
pi = [pw[1], pr[0], pe[0]]
|
77
|
+
pw[1].sync = true
|
78
|
+
if defined? yield
|
79
|
+
begin
|
80
|
+
return yield(*pi)
|
81
|
+
ensure
|
82
|
+
pi.each{|p| p.close unless p.closed?}
|
83
|
+
end
|
84
|
+
end
|
85
|
+
pi
|
86
|
+
end
|
87
|
+
module_function :popen3
|
88
|
+
end
|
89
|
+
|
90
|
+
if $0 == __FILE__
|
91
|
+
a = Open3.popen3("nroff -man")
|
92
|
+
Thread.start do
|
93
|
+
while line = gets
|
94
|
+
a[0].print line
|
95
|
+
end
|
96
|
+
a[0].close
|
97
|
+
end
|
98
|
+
while line = a[1].gets
|
99
|
+
print ":", line
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,1790 @@
|
|
1
|
+
#
|
2
|
+
# optparse.rb - command-line option analysis with the OptionParser class.
|
3
|
+
#
|
4
|
+
# Author:: Nobu Nakada
|
5
|
+
# Documentation:: Nobu Nakada and Gavin Sinclair.
|
6
|
+
#
|
7
|
+
# See OptionParser for documentation.
|
8
|
+
#
|
9
|
+
|
10
|
+
|
11
|
+
# == Developer Documentation (not for RDoc output)
|
12
|
+
#
|
13
|
+
# === Class tree
|
14
|
+
#
|
15
|
+
# - OptionParser:: front end
|
16
|
+
# - OptionParser::Switch:: each switches
|
17
|
+
# - OptionParser::List:: options list
|
18
|
+
# - OptionParser::ParseError:: errors on parsing
|
19
|
+
# - OptionParser::AmbiguousOption
|
20
|
+
# - OptionParser::NeedlessArgument
|
21
|
+
# - OptionParser::MissingArgument
|
22
|
+
# - OptionParser::InvalidOption
|
23
|
+
# - OptionParser::InvalidArgument
|
24
|
+
# - OptionParser::AmbiguousArgument
|
25
|
+
#
|
26
|
+
# === Object relationship diagram
|
27
|
+
#
|
28
|
+
# +--------------+
|
29
|
+
# | OptionParser |<>-----+
|
30
|
+
# +--------------+ | +--------+
|
31
|
+
# | ,-| Switch |
|
32
|
+
# on_head -------->+---------------+ / +--------+
|
33
|
+
# accept/reject -->| List |<|>-
|
34
|
+
# | |<|>- +----------+
|
35
|
+
# on ------------->+---------------+ `-| argument |
|
36
|
+
# : : | class |
|
37
|
+
# +---------------+ |==========|
|
38
|
+
# on_tail -------->| | |pattern |
|
39
|
+
# +---------------+ |----------|
|
40
|
+
# OptionParser.accept ->| DefaultList | |converter |
|
41
|
+
# reject |(shared between| +----------+
|
42
|
+
# | all instances)|
|
43
|
+
# +---------------+
|
44
|
+
#
|
45
|
+
# == OptionParser
|
46
|
+
#
|
47
|
+
# === Introduction
|
48
|
+
#
|
49
|
+
# OptionParser is a class for command-line option analysis. It is much more
|
50
|
+
# advanced, yet also easier to use, than GetoptLong, and is a more Ruby-oriented
|
51
|
+
# solution.
|
52
|
+
#
|
53
|
+
# === Features
|
54
|
+
#
|
55
|
+
# 1. The argument specification and the code to handle it are written in the
|
56
|
+
# same place.
|
57
|
+
# 2. It can output an option summary; you don't need to maintain this string
|
58
|
+
# separately.
|
59
|
+
# 3. Optional and mandatory arguments are specified very gracefully.
|
60
|
+
# 4. Arguments can be automatically converted to a specified class.
|
61
|
+
# 5. Arguments can be restricted to a certain set.
|
62
|
+
#
|
63
|
+
# All of these features are demonstrated in the examples below.
|
64
|
+
#
|
65
|
+
# === Minimal example
|
66
|
+
#
|
67
|
+
# require 'optparse'
|
68
|
+
#
|
69
|
+
# options = {}
|
70
|
+
# OptionParser.new do |opts|
|
71
|
+
# opts.banner = "Usage: example.rb [options]"
|
72
|
+
#
|
73
|
+
# opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
74
|
+
# options[:verbose] = v
|
75
|
+
# end
|
76
|
+
# end.parse!
|
77
|
+
#
|
78
|
+
# p options
|
79
|
+
# p ARGV
|
80
|
+
#
|
81
|
+
# === Complete example
|
82
|
+
#
|
83
|
+
# The following example is a complete Ruby program. You can run it and see the
|
84
|
+
# effect of specifying various options. This is probably the best way to learn
|
85
|
+
# the features of +optparse+.
|
86
|
+
#
|
87
|
+
# require 'optparse'
|
88
|
+
# require 'optparse/time'
|
89
|
+
# require 'ostruct'
|
90
|
+
# require 'pp'
|
91
|
+
#
|
92
|
+
# class OptparseExample
|
93
|
+
#
|
94
|
+
# CODES = %w[iso-2022-jp shift_jis euc-jp utf8 binary]
|
95
|
+
# CODE_ALIASES = { "jis" => "iso-2022-jp", "sjis" => "shift_jis" }
|
96
|
+
#
|
97
|
+
# #
|
98
|
+
# # Return a structure describing the options.
|
99
|
+
# #
|
100
|
+
# def self.parse(args)
|
101
|
+
# # The options specified on the command line will be collected in *options*.
|
102
|
+
# # We set default values here.
|
103
|
+
# options = OpenStruct.new
|
104
|
+
# options.library = []
|
105
|
+
# options.inplace = false
|
106
|
+
# options.encoding = "utf8"
|
107
|
+
# options.transfer_type = :auto
|
108
|
+
# options.verbose = false
|
109
|
+
#
|
110
|
+
# opts = OptionParser.new do |opts|
|
111
|
+
# opts.banner = "Usage: example.rb [options]"
|
112
|
+
#
|
113
|
+
# opts.separator ""
|
114
|
+
# opts.separator "Specific options:"
|
115
|
+
#
|
116
|
+
# # Mandatory argument.
|
117
|
+
# opts.on("-r", "--require LIBRARY",
|
118
|
+
# "Require the LIBRARY before executing your script") do |lib|
|
119
|
+
# options.library << lib
|
120
|
+
# end
|
121
|
+
#
|
122
|
+
# # Optional argument; multi-line description.
|
123
|
+
# opts.on("-i", "--inplace [EXTENSION]",
|
124
|
+
# "Edit ARGV files in place",
|
125
|
+
# " (make backup if EXTENSION supplied)") do |ext|
|
126
|
+
# options.inplace = true
|
127
|
+
# options.extension = ext || ''
|
128
|
+
# options.extension.sub!(/\A\.?(?=.)/, ".") # Ensure extension begins with dot.
|
129
|
+
# end
|
130
|
+
#
|
131
|
+
# # Cast 'delay' argument to a Float.
|
132
|
+
# opts.on("--delay N", Float, "Delay N seconds before executing") do |n|
|
133
|
+
# options.delay = n
|
134
|
+
# end
|
135
|
+
#
|
136
|
+
# # Cast 'time' argument to a Time object.
|
137
|
+
# opts.on("-t", "--time [TIME]", Time, "Begin execution at given time") do |time|
|
138
|
+
# options.time = time
|
139
|
+
# end
|
140
|
+
#
|
141
|
+
# # Cast to octal integer.
|
142
|
+
# opts.on("-F", "--irs [OCTAL]", OptionParser::OctalInteger,
|
143
|
+
# "Specify record separator (default \\0)") do |rs|
|
144
|
+
# options.record_separator = rs
|
145
|
+
# end
|
146
|
+
#
|
147
|
+
# # List of arguments.
|
148
|
+
# opts.on("--list x,y,z", Array, "Example 'list' of arguments") do |list|
|
149
|
+
# options.list = list
|
150
|
+
# end
|
151
|
+
#
|
152
|
+
# # Keyword completion. We are specifying a specific set of arguments (CODES
|
153
|
+
# # and CODE_ALIASES - notice the latter is a Hash), and the user may provide
|
154
|
+
# # the shortest unambiguous text.
|
155
|
+
# code_list = (CODE_ALIASES.keys + CODES).join(',')
|
156
|
+
# opts.on("--code CODE", CODES, CODE_ALIASES, "Select encoding",
|
157
|
+
# " (#{code_list})") do |encoding|
|
158
|
+
# options.encoding = encoding
|
159
|
+
# end
|
160
|
+
#
|
161
|
+
# # Optional argument with keyword completion.
|
162
|
+
# opts.on("--type [TYPE]", [:text, :binary, :auto],
|
163
|
+
# "Select transfer type (text, binary, auto)") do |t|
|
164
|
+
# options.transfer_type = t
|
165
|
+
# end
|
166
|
+
#
|
167
|
+
# # Boolean switch.
|
168
|
+
# opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
169
|
+
# options.verbose = v
|
170
|
+
# end
|
171
|
+
#
|
172
|
+
# opts.separator ""
|
173
|
+
# opts.separator "Common options:"
|
174
|
+
#
|
175
|
+
# # No argument, shows at tail. This will print an options summary.
|
176
|
+
# # Try it and see!
|
177
|
+
# opts.on_tail("-h", "--help", "Show this message") do
|
178
|
+
# puts opts
|
179
|
+
# exit
|
180
|
+
# end
|
181
|
+
#
|
182
|
+
# # Another typical switch to print the version.
|
183
|
+
# opts.on_tail("--version", "Show version") do
|
184
|
+
# puts OptionParser::Version.join('.')
|
185
|
+
# exit
|
186
|
+
# end
|
187
|
+
# end
|
188
|
+
#
|
189
|
+
# opts.parse!(args)
|
190
|
+
# options
|
191
|
+
# end # parse()
|
192
|
+
#
|
193
|
+
# end # class OptparseExample
|
194
|
+
#
|
195
|
+
# options = OptparseExample.parse(ARGV)
|
196
|
+
# pp options
|
197
|
+
#
|
198
|
+
# === Further documentation
|
199
|
+
#
|
200
|
+
# The above examples should be enough to learn how to use this class. If you
|
201
|
+
# have any questions, email me (gsinclair@soyabean.com.au) and I will update
|
202
|
+
# this document.
|
203
|
+
#
|
204
|
+
class OptionParser
|
205
|
+
# :stopdoc:
|
206
|
+
RCSID = %w$Id: optparse.rb 13823 2007-11-04 20:17:06Z nobu $[1..-1].each {|s| s.freeze}.freeze
|
207
|
+
Version = (RCSID[1].split('.').collect {|s| s.to_i}.extend(Comparable).freeze if RCSID[1])
|
208
|
+
LastModified = (Time.gm(*RCSID[2, 2].join('-').scan(/\d+/).collect {|s| s.to_i}) if RCSID[2])
|
209
|
+
Release = RCSID[2]
|
210
|
+
|
211
|
+
NoArgument = [NO_ARGUMENT = :NONE, nil].freeze
|
212
|
+
RequiredArgument = [REQUIRED_ARGUMENT = :REQUIRED, true].freeze
|
213
|
+
OptionalArgument = [OPTIONAL_ARGUMENT = :OPTIONAL, false].freeze
|
214
|
+
# :startdoc:
|
215
|
+
|
216
|
+
#
|
217
|
+
# Keyword completion module. This allows partial arguments to be specified
|
218
|
+
# and resolved against a list of acceptable values.
|
219
|
+
#
|
220
|
+
module Completion
|
221
|
+
def complete(key, icase = false, pat = nil)
|
222
|
+
pat ||= Regexp.new('\A' + Regexp.quote(key).gsub(/\w+\b/, '\&\w*'),
|
223
|
+
icase)
|
224
|
+
canon, sw, k, v, cn = nil
|
225
|
+
candidates = []
|
226
|
+
each do |k, *v|
|
227
|
+
(if Regexp === k
|
228
|
+
kn = nil
|
229
|
+
k === key
|
230
|
+
else
|
231
|
+
kn = defined?(k.id2name) ? k.id2name : k
|
232
|
+
pat === kn
|
233
|
+
end) or next
|
234
|
+
v << k if v.empty?
|
235
|
+
candidates << [k, v, kn]
|
236
|
+
end
|
237
|
+
candidates = candidates.sort_by {|k, v, kn| kn.size}
|
238
|
+
if candidates.size == 1
|
239
|
+
canon, sw, * = candidates[0]
|
240
|
+
elsif candidates.size > 1
|
241
|
+
canon, sw, cn = candidates.shift
|
242
|
+
candidates.each do |k, v, kn|
|
243
|
+
next if sw == v
|
244
|
+
if String === cn and String === kn
|
245
|
+
if cn.rindex(kn, 0)
|
246
|
+
canon, sw, cn = k, v, kn
|
247
|
+
next
|
248
|
+
elsif kn.rindex(cn, 0)
|
249
|
+
next
|
250
|
+
end
|
251
|
+
end
|
252
|
+
throw :ambiguous, key
|
253
|
+
end
|
254
|
+
end
|
255
|
+
if canon
|
256
|
+
block_given? or return key, *sw
|
257
|
+
yield(key, *sw)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
def convert(opt = nil, val = nil, *)
|
262
|
+
val
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
|
267
|
+
#
|
268
|
+
# Map from option/keyword string to object with completion.
|
269
|
+
#
|
270
|
+
class OptionMap < Hash
|
271
|
+
include Completion
|
272
|
+
end
|
273
|
+
|
274
|
+
|
275
|
+
#
|
276
|
+
# Individual switch class. Not important to the user.
|
277
|
+
#
|
278
|
+
# Defined within Switch are several Switch-derived classes: NoArgument,
|
279
|
+
# RequiredArgument, etc.
|
280
|
+
#
|
281
|
+
class Switch
|
282
|
+
attr_reader :pattern, :conv, :short, :long, :arg, :desc, :block
|
283
|
+
|
284
|
+
#
|
285
|
+
# Guesses argument style from +arg+. Returns corresponding
|
286
|
+
# OptionParser::Switch class (OptionalArgument, etc.).
|
287
|
+
#
|
288
|
+
def self.guess(arg)
|
289
|
+
case arg
|
290
|
+
when ""
|
291
|
+
t = self
|
292
|
+
when /\A=?\[/
|
293
|
+
t = Switch::OptionalArgument
|
294
|
+
when /\A\s+\[/
|
295
|
+
t = Switch::PlacedArgument
|
296
|
+
else
|
297
|
+
t = Switch::RequiredArgument
|
298
|
+
end
|
299
|
+
self >= t or incompatible_argument_styles(arg, t)
|
300
|
+
t
|
301
|
+
end
|
302
|
+
|
303
|
+
def self.incompatible_argument_styles(arg, t)
|
304
|
+
raise ArgumentError, "#{arg}: incompatible argument styles\n #{self}, #{t}"
|
305
|
+
end
|
306
|
+
|
307
|
+
def self.pattern
|
308
|
+
NilClass
|
309
|
+
end
|
310
|
+
|
311
|
+
def initialize(pattern = nil, conv = nil,
|
312
|
+
short = nil, long = nil, arg = nil,
|
313
|
+
desc = ([] if short or long), block = Proc.new)
|
314
|
+
raise if Array === pattern
|
315
|
+
@pattern, @conv, @short, @long, @arg, @desc, @block =
|
316
|
+
pattern, conv, short, long, arg, desc, block
|
317
|
+
end
|
318
|
+
|
319
|
+
#
|
320
|
+
# Parses +arg+ and returns rest of +arg+ and matched portion to the
|
321
|
+
# argument pattern. Yields when the pattern doesn't match substring.
|
322
|
+
#
|
323
|
+
def parse_arg(arg)
|
324
|
+
pattern or return nil, arg
|
325
|
+
unless m = pattern.match(arg)
|
326
|
+
yield(InvalidArgument, arg)
|
327
|
+
return arg, nil
|
328
|
+
end
|
329
|
+
if String === m
|
330
|
+
m = [s = m]
|
331
|
+
else
|
332
|
+
m = m.to_a
|
333
|
+
s = m[0]
|
334
|
+
return nil, m unless String === s
|
335
|
+
end
|
336
|
+
raise InvalidArgument, arg unless arg.rindex(s, 0)
|
337
|
+
return nil, m if s.length == arg.length
|
338
|
+
yield(InvalidArgument, arg) # didn't match whole arg
|
339
|
+
return arg[s.length..-1], m
|
340
|
+
end
|
341
|
+
private :parse_arg
|
342
|
+
|
343
|
+
#
|
344
|
+
# Parses argument, converts and returns +arg+, +block+ and result of
|
345
|
+
# conversion. Yields at semi-error condition instead of raising an
|
346
|
+
# exception.
|
347
|
+
#
|
348
|
+
def conv_arg(arg, val = nil)
|
349
|
+
if conv
|
350
|
+
val = conv.call(*val)
|
351
|
+
else
|
352
|
+
val = proc {|val| val}.call(*val)
|
353
|
+
end
|
354
|
+
return arg, block, val
|
355
|
+
end
|
356
|
+
private :conv_arg
|
357
|
+
|
358
|
+
#
|
359
|
+
# Produces the summary text. Each line of the summary is yielded to the
|
360
|
+
# block (without newline).
|
361
|
+
#
|
362
|
+
# +sdone+:: Already summarized short style options keyed hash.
|
363
|
+
# +ldone+:: Already summarized long style options keyed hash.
|
364
|
+
# +width+:: Width of left side (option part). In other words, the right
|
365
|
+
# side (description part) starts after +width+ columns.
|
366
|
+
# +max+:: Maximum width of left side -> the options are filled within
|
367
|
+
# +max+ columns.
|
368
|
+
# +indent+:: Prefix string indents all summarized lines.
|
369
|
+
#
|
370
|
+
def summarize(sdone = [], ldone = [], width = 1, max = width - 1, indent = "")
|
371
|
+
sopts, lopts, s = [], [], nil
|
372
|
+
@short.each {|s| sdone.fetch(s) {sopts << s}; sdone[s] = true} if @short
|
373
|
+
@long.each {|s| ldone.fetch(s) {lopts << s}; ldone[s] = true} if @long
|
374
|
+
return if sopts.empty? and lopts.empty? # completely hidden
|
375
|
+
|
376
|
+
left = [sopts.join(', ')]
|
377
|
+
right = desc.dup
|
378
|
+
|
379
|
+
while s = lopts.shift
|
380
|
+
l = left[-1].length + s.length
|
381
|
+
l += arg.length if left.size == 1 && arg
|
382
|
+
l < max or sopts.empty? or left << ''
|
383
|
+
left[-1] << if left[-1].empty? then ' ' * 4 else ', ' end << s
|
384
|
+
end
|
385
|
+
|
386
|
+
left[0] << arg if arg
|
387
|
+
mlen = left.collect {|s| s.length}.max.to_i
|
388
|
+
while mlen > width and l = left.shift
|
389
|
+
mlen = left.collect {|s| s.length}.max.to_i if l.length == mlen
|
390
|
+
yield(indent + l)
|
391
|
+
end
|
392
|
+
|
393
|
+
while begin l = left.shift; r = right.shift; l or r end
|
394
|
+
l = l.to_s.ljust(width) + ' ' + r if r and !r.empty?
|
395
|
+
yield(indent + l)
|
396
|
+
end
|
397
|
+
|
398
|
+
self
|
399
|
+
end
|
400
|
+
|
401
|
+
def add_banner(to) # :nodoc:
|
402
|
+
unless @short or @long
|
403
|
+
s = desc.join
|
404
|
+
to << " [" + s + "]..." unless s.empty?
|
405
|
+
end
|
406
|
+
to
|
407
|
+
end
|
408
|
+
|
409
|
+
def match_nonswitch?(str) # :nodoc:
|
410
|
+
@pattern =~ str unless @short or @long
|
411
|
+
end
|
412
|
+
|
413
|
+
#
|
414
|
+
# Main name of the switch.
|
415
|
+
#
|
416
|
+
def switch_name
|
417
|
+
(long.first || short.first).sub(/\A-+(?:\[no-\])?/, '')
|
418
|
+
end
|
419
|
+
|
420
|
+
#
|
421
|
+
# Switch that takes no arguments.
|
422
|
+
#
|
423
|
+
class NoArgument < self
|
424
|
+
|
425
|
+
#
|
426
|
+
# Raises an exception if any arguments given.
|
427
|
+
#
|
428
|
+
def parse(arg, argv)
|
429
|
+
yield(NeedlessArgument, arg) if arg
|
430
|
+
conv_arg(arg)
|
431
|
+
end
|
432
|
+
|
433
|
+
def self.incompatible_argument_styles(*)
|
434
|
+
end
|
435
|
+
|
436
|
+
def self.pattern
|
437
|
+
Object
|
438
|
+
end
|
439
|
+
end
|
440
|
+
|
441
|
+
#
|
442
|
+
# Switch that takes an argument.
|
443
|
+
#
|
444
|
+
class RequiredArgument < self
|
445
|
+
|
446
|
+
#
|
447
|
+
# Raises an exception if argument is not present.
|
448
|
+
#
|
449
|
+
def parse(arg, argv)
|
450
|
+
unless arg
|
451
|
+
raise MissingArgument if argv.empty?
|
452
|
+
arg = argv.shift
|
453
|
+
end
|
454
|
+
conv_arg(*parse_arg(arg) {|*exc| raise(*exc)})
|
455
|
+
end
|
456
|
+
end
|
457
|
+
|
458
|
+
#
|
459
|
+
# Switch that can omit argument.
|
460
|
+
#
|
461
|
+
class OptionalArgument < self
|
462
|
+
|
463
|
+
#
|
464
|
+
# Parses argument if given, or uses default value.
|
465
|
+
#
|
466
|
+
def parse(arg, argv, &error)
|
467
|
+
if arg
|
468
|
+
conv_arg(*parse_arg(arg, &error))
|
469
|
+
else
|
470
|
+
conv_arg(arg)
|
471
|
+
end
|
472
|
+
end
|
473
|
+
end
|
474
|
+
|
475
|
+
#
|
476
|
+
# Switch that takes an argument, which does not begin with '-'.
|
477
|
+
#
|
478
|
+
class PlacedArgument < self
|
479
|
+
|
480
|
+
#
|
481
|
+
# Returns nil if argument is not present or begins with '-'.
|
482
|
+
#
|
483
|
+
def parse(arg, argv, &error)
|
484
|
+
if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
|
485
|
+
return nil, block, nil
|
486
|
+
end
|
487
|
+
opt = (val = parse_arg(val, &error))[1]
|
488
|
+
val = conv_arg(*val)
|
489
|
+
if opt and !arg
|
490
|
+
argv.shift
|
491
|
+
else
|
492
|
+
val[0] = nil
|
493
|
+
end
|
494
|
+
val
|
495
|
+
end
|
496
|
+
end
|
497
|
+
end
|
498
|
+
|
499
|
+
#
|
500
|
+
# Simple option list providing mapping from short and/or long option
|
501
|
+
# string to OptionParser::Switch and mapping from acceptable argument to
|
502
|
+
# matching pattern and converter pair. Also provides summary feature.
|
503
|
+
#
|
504
|
+
class List
|
505
|
+
# Map from acceptable argument types to pattern and converter pairs.
|
506
|
+
attr_reader :atype
|
507
|
+
|
508
|
+
# Map from short style option switches to actual switch objects.
|
509
|
+
attr_reader :short
|
510
|
+
|
511
|
+
# Map from long style option switches to actual switch objects.
|
512
|
+
attr_reader :long
|
513
|
+
|
514
|
+
# List of all switches and summary string.
|
515
|
+
attr_reader :list
|
516
|
+
|
517
|
+
#
|
518
|
+
# Just initializes all instance variables.
|
519
|
+
#
|
520
|
+
def initialize
|
521
|
+
@atype = {}
|
522
|
+
@short = OptionMap.new
|
523
|
+
@long = OptionMap.new
|
524
|
+
@list = []
|
525
|
+
end
|
526
|
+
|
527
|
+
#
|
528
|
+
# See OptionParser.accept.
|
529
|
+
#
|
530
|
+
def accept(t, pat = /.*/nm, &block)
|
531
|
+
if pat
|
532
|
+
pat.respond_to?(:match) or raise TypeError, "has no `match'"
|
533
|
+
else
|
534
|
+
pat = t if t.respond_to?(:match)
|
535
|
+
end
|
536
|
+
unless block
|
537
|
+
block = pat.method(:convert).to_proc if pat.respond_to?(:convert)
|
538
|
+
end
|
539
|
+
@atype[t] = [pat, block]
|
540
|
+
end
|
541
|
+
|
542
|
+
#
|
543
|
+
# See OptionParser.reject.
|
544
|
+
#
|
545
|
+
def reject(t)
|
546
|
+
@atype.delete(t)
|
547
|
+
end
|
548
|
+
|
549
|
+
#
|
550
|
+
# Adds +sw+ according to +sopts+, +lopts+ and +nlopts+.
|
551
|
+
#
|
552
|
+
# +sw+:: OptionParser::Switch instance to be added.
|
553
|
+
# +sopts+:: Short style option list.
|
554
|
+
# +lopts+:: Long style option list.
|
555
|
+
# +nlopts+:: Negated long style options list.
|
556
|
+
#
|
557
|
+
def update(sw, sopts, lopts, nsw = nil, nlopts = nil)
|
558
|
+
o = nil
|
559
|
+
sopts.each {|o| @short[o] = sw} if sopts
|
560
|
+
lopts.each {|o| @long[o] = sw} if lopts
|
561
|
+
nlopts.each {|o| @long[o] = nsw} if nsw and nlopts
|
562
|
+
used = @short.invert.update(@long.invert)
|
563
|
+
@list.delete_if {|o| Switch === o and !used[o]}
|
564
|
+
end
|
565
|
+
private :update
|
566
|
+
|
567
|
+
#
|
568
|
+
# Inserts +switch+ at the head of the list, and associates short, long
|
569
|
+
# and negated long options. Arguments are:
|
570
|
+
#
|
571
|
+
# +switch+:: OptionParser::Switch instance to be inserted.
|
572
|
+
# +short_opts+:: List of short style options.
|
573
|
+
# +long_opts+:: List of long style options.
|
574
|
+
# +nolong_opts+:: List of long style options with "no-" prefix.
|
575
|
+
#
|
576
|
+
# prepend(switch, short_opts, long_opts, nolong_opts)
|
577
|
+
#
|
578
|
+
def prepend(*args)
|
579
|
+
update(*args)
|
580
|
+
@list.unshift(args[0])
|
581
|
+
end
|
582
|
+
|
583
|
+
#
|
584
|
+
# Appends +switch+ at the tail of the list, and associates short, long
|
585
|
+
# and negated long options. Arguments are:
|
586
|
+
#
|
587
|
+
# +switch+:: OptionParser::Switch instance to be inserted.
|
588
|
+
# +short_opts+:: List of short style options.
|
589
|
+
# +long_opts+:: List of long style options.
|
590
|
+
# +nolong_opts+:: List of long style options with "no-" prefix.
|
591
|
+
#
|
592
|
+
# append(switch, short_opts, long_opts, nolong_opts)
|
593
|
+
#
|
594
|
+
def append(*args)
|
595
|
+
update(*args)
|
596
|
+
@list.push(args[0])
|
597
|
+
end
|
598
|
+
|
599
|
+
#
|
600
|
+
# Searches +key+ in +id+ list. The result is returned or yielded if a
|
601
|
+
# block is given. If it isn't found, nil is returned.
|
602
|
+
#
|
603
|
+
def search(id, key)
|
604
|
+
if list = __send__(id)
|
605
|
+
val = list.fetch(key) {return nil}
|
606
|
+
block_given? ? yield(val) : val
|
607
|
+
end
|
608
|
+
end
|
609
|
+
|
610
|
+
#
|
611
|
+
# Searches list +id+ for +opt+ and the optional patterns for completion
|
612
|
+
# +pat+. If +icase+ is true, the search is case insensitive. The result
|
613
|
+
# is returned or yielded if a block is given. If it isn't found, nil is
|
614
|
+
# returned.
|
615
|
+
#
|
616
|
+
def complete(id, opt, icase = false, *pat, &block)
|
617
|
+
__send__(id).complete(opt, icase, *pat, &block)
|
618
|
+
end
|
619
|
+
|
620
|
+
#
|
621
|
+
# Iterates over each option, passing the option to the +block+.
|
622
|
+
#
|
623
|
+
def each_option(&block)
|
624
|
+
list.each(&block)
|
625
|
+
end
|
626
|
+
|
627
|
+
#
|
628
|
+
# Creates the summary table, passing each line to the +block+ (without
|
629
|
+
# newline). The arguments +args+ are passed along to the summarize
|
630
|
+
# method which is called on every option.
|
631
|
+
#
|
632
|
+
def summarize(*args, &block)
|
633
|
+
list.each do |opt|
|
634
|
+
if opt.respond_to?(:summarize) # perhaps OptionParser::Switch
|
635
|
+
opt.summarize(*args, &block)
|
636
|
+
elsif !opt
|
637
|
+
yield("")
|
638
|
+
elsif opt.respond_to?(:each_line)
|
639
|
+
opt.each_line(&block)
|
640
|
+
else
|
641
|
+
opt.each(&block)
|
642
|
+
end
|
643
|
+
end
|
644
|
+
end
|
645
|
+
|
646
|
+
def add_banner(to) # :nodoc:
|
647
|
+
list.each do |opt|
|
648
|
+
if opt.respond_to?(:add_banner)
|
649
|
+
opt.add_banner(to)
|
650
|
+
end
|
651
|
+
end
|
652
|
+
to
|
653
|
+
end
|
654
|
+
end
|
655
|
+
|
656
|
+
#
|
657
|
+
# Hash with completion search feature. See OptionParser::Completion.
|
658
|
+
#
|
659
|
+
class CompletingHash < Hash
|
660
|
+
include Completion
|
661
|
+
|
662
|
+
#
|
663
|
+
# Completion for hash key.
|
664
|
+
#
|
665
|
+
def match(key)
|
666
|
+
return key, *fetch(key) {
|
667
|
+
raise AmbiguousArgument, catch(:ambiguous) {return complete(key)}
|
668
|
+
}
|
669
|
+
end
|
670
|
+
end
|
671
|
+
|
672
|
+
# :stopdoc:
|
673
|
+
|
674
|
+
#
|
675
|
+
# Enumeration of acceptable argument styles. Possible values are:
|
676
|
+
#
|
677
|
+
# NO_ARGUMENT:: The switch takes no arguments. (:NONE)
|
678
|
+
# REQUIRED_ARGUMENT:: The switch requires an argument. (:REQUIRED)
|
679
|
+
# OPTIONAL_ARGUMENT:: The switch requires an optional argument. (:OPTIONAL)
|
680
|
+
#
|
681
|
+
# Use like --switch=argument (long style) or -Xargument (short style). For
|
682
|
+
# short style, only portion matched to argument pattern is dealed as
|
683
|
+
# argument.
|
684
|
+
#
|
685
|
+
ArgumentStyle = {}
|
686
|
+
NoArgument.each {|el| ArgumentStyle[el] = Switch::NoArgument}
|
687
|
+
RequiredArgument.each {|el| ArgumentStyle[el] = Switch::RequiredArgument}
|
688
|
+
OptionalArgument.each {|el| ArgumentStyle[el] = Switch::OptionalArgument}
|
689
|
+
ArgumentStyle.freeze
|
690
|
+
|
691
|
+
#
|
692
|
+
# Switches common used such as '--', and also provides default
|
693
|
+
# argument classes
|
694
|
+
#
|
695
|
+
DefaultList = List.new
|
696
|
+
DefaultList.short['-'] = Switch::NoArgument.new {}
|
697
|
+
DefaultList.long[''] = Switch::NoArgument.new {throw :terminate}
|
698
|
+
|
699
|
+
#
|
700
|
+
# Default options for ARGV, which never appear in option summary.
|
701
|
+
#
|
702
|
+
Officious = {}
|
703
|
+
|
704
|
+
#
|
705
|
+
# --help
|
706
|
+
# Shows option summary.
|
707
|
+
#
|
708
|
+
Officious['help'] = proc do |parser|
|
709
|
+
Switch::NoArgument.new do
|
710
|
+
puts parser.help
|
711
|
+
exit
|
712
|
+
end
|
713
|
+
end
|
714
|
+
|
715
|
+
#
|
716
|
+
# --version
|
717
|
+
# Shows version string if Version is defined.
|
718
|
+
#
|
719
|
+
Officious['version'] = proc do |parser|
|
720
|
+
Switch::OptionalArgument.new do |pkg|
|
721
|
+
if pkg
|
722
|
+
begin
|
723
|
+
require 'optparse/version'
|
724
|
+
rescue LoadError
|
725
|
+
else
|
726
|
+
show_version(*pkg.split(/,/)) or
|
727
|
+
abort("#{parser.program_name}: no version found in package #{pkg}")
|
728
|
+
exit
|
729
|
+
end
|
730
|
+
end
|
731
|
+
v = parser.ver or abort("#{parser.program_name}: version unknown")
|
732
|
+
puts v
|
733
|
+
exit
|
734
|
+
end
|
735
|
+
end
|
736
|
+
|
737
|
+
# :startdoc:
|
738
|
+
|
739
|
+
#
|
740
|
+
# Class methods
|
741
|
+
#
|
742
|
+
|
743
|
+
#
|
744
|
+
# Initializes a new instance and evaluates the optional block in context
|
745
|
+
# of the instance. Arguments +args+ are passed to #new, see there for
|
746
|
+
# description of parameters.
|
747
|
+
#
|
748
|
+
# This method is *deprecated*, its behavior corresponds to the older #new
|
749
|
+
# method.
|
750
|
+
#
|
751
|
+
def self.with(*args, &block)
|
752
|
+
opts = new(*args)
|
753
|
+
opts.instance_eval(&block)
|
754
|
+
opts
|
755
|
+
end
|
756
|
+
|
757
|
+
#
|
758
|
+
# Returns an incremented value of +default+ according to +arg+.
|
759
|
+
#
|
760
|
+
def self.inc(arg, default = nil)
|
761
|
+
case arg
|
762
|
+
when Integer
|
763
|
+
arg.nonzero?
|
764
|
+
when nil
|
765
|
+
default.to_i + 1
|
766
|
+
end
|
767
|
+
end
|
768
|
+
def inc(*args)
|
769
|
+
self.class.inc(*args)
|
770
|
+
end
|
771
|
+
|
772
|
+
#
|
773
|
+
# Initializes the instance and yields itself if called with a block.
|
774
|
+
#
|
775
|
+
# +banner+:: Banner message.
|
776
|
+
# +width+:: Summary width.
|
777
|
+
# +indent+:: Summary indent.
|
778
|
+
#
|
779
|
+
def initialize(banner = nil, width = 32, indent = ' ' * 4)
|
780
|
+
@stack = [DefaultList, List.new, List.new]
|
781
|
+
@program_name = nil
|
782
|
+
@banner = banner
|
783
|
+
@summary_width = width
|
784
|
+
@summary_indent = indent
|
785
|
+
@default_argv = ARGV
|
786
|
+
add_officious
|
787
|
+
yield self if block_given?
|
788
|
+
end
|
789
|
+
|
790
|
+
def add_officious # :nodoc:
|
791
|
+
list = base()
|
792
|
+
Officious.each do |opt, block|
|
793
|
+
list.long[opt] ||= block.call(self)
|
794
|
+
end
|
795
|
+
end
|
796
|
+
|
797
|
+
#
|
798
|
+
# Terminates option parsing. Optional parameter +arg+ is a string pushed
|
799
|
+
# back to be the first non-option argument.
|
800
|
+
#
|
801
|
+
def terminate(arg = nil)
|
802
|
+
self.class.terminate(arg)
|
803
|
+
end
|
804
|
+
def self.terminate(arg = nil)
|
805
|
+
throw :terminate, arg
|
806
|
+
end
|
807
|
+
|
808
|
+
@stack = [DefaultList]
|
809
|
+
def self.top() DefaultList end
|
810
|
+
|
811
|
+
#
|
812
|
+
# Directs to accept specified class +t+. The argument string is passed to
|
813
|
+
# the block in which it should be converted to the desired class.
|
814
|
+
#
|
815
|
+
# +t+:: Argument class specifier, any object including Class.
|
816
|
+
# +pat+:: Pattern for argument, defaults to +t+ if it responds to match.
|
817
|
+
#
|
818
|
+
# accept(t, pat, &block)
|
819
|
+
#
|
820
|
+
def accept(*args, &blk) top.accept(*args, &blk) end
|
821
|
+
#
|
822
|
+
# See #accept.
|
823
|
+
#
|
824
|
+
def self.accept(*args, &blk) top.accept(*args, &blk) end
|
825
|
+
|
826
|
+
#
|
827
|
+
# Directs to reject specified class argument.
|
828
|
+
#
|
829
|
+
# +t+:: Argument class speficier, any object including Class.
|
830
|
+
#
|
831
|
+
# reject(t)
|
832
|
+
#
|
833
|
+
def reject(*args, &blk) top.reject(*args, &blk) end
|
834
|
+
#
|
835
|
+
# See #reject.
|
836
|
+
#
|
837
|
+
def self.reject(*args, &blk) top.reject(*args, &blk) end
|
838
|
+
|
839
|
+
#
|
840
|
+
# Instance methods
|
841
|
+
#
|
842
|
+
|
843
|
+
# Heading banner preceding summary.
|
844
|
+
attr_writer :banner
|
845
|
+
|
846
|
+
# Program name to be emitted in error message and default banner,
|
847
|
+
# defaults to $0.
|
848
|
+
attr_writer :program_name
|
849
|
+
|
850
|
+
# Width for option list portion of summary. Must be Numeric.
|
851
|
+
attr_accessor :summary_width
|
852
|
+
|
853
|
+
# Indentation for summary. Must be String (or have + String method).
|
854
|
+
attr_accessor :summary_indent
|
855
|
+
|
856
|
+
# Strings to be parsed in default.
|
857
|
+
attr_accessor :default_argv
|
858
|
+
|
859
|
+
#
|
860
|
+
# Heading banner preceding summary.
|
861
|
+
#
|
862
|
+
def banner
|
863
|
+
unless @banner
|
864
|
+
@banner = "Usage: #{program_name} [options]"
|
865
|
+
visit(:add_banner, @banner)
|
866
|
+
end
|
867
|
+
@banner
|
868
|
+
end
|
869
|
+
|
870
|
+
#
|
871
|
+
# Program name to be emitted in error message and default banner, defaults
|
872
|
+
# to $0.
|
873
|
+
#
|
874
|
+
def program_name
|
875
|
+
@program_name || File.basename($0, '.*')
|
876
|
+
end
|
877
|
+
|
878
|
+
# for experimental cascading :-)
|
879
|
+
alias set_banner banner=
|
880
|
+
alias set_program_name program_name=
|
881
|
+
alias set_summary_width summary_width=
|
882
|
+
alias set_summary_indent summary_indent=
|
883
|
+
|
884
|
+
# Version
|
885
|
+
attr_writer :version
|
886
|
+
# Release code
|
887
|
+
attr_writer :release
|
888
|
+
|
889
|
+
#
|
890
|
+
# Version
|
891
|
+
#
|
892
|
+
def version
|
893
|
+
@version || (defined?(::Version) && ::Version)
|
894
|
+
end
|
895
|
+
|
896
|
+
#
|
897
|
+
# Release code
|
898
|
+
#
|
899
|
+
def release
|
900
|
+
@release || (defined?(::Release) && ::Release) || (defined?(::RELEASE) && ::RELEASE)
|
901
|
+
end
|
902
|
+
|
903
|
+
#
|
904
|
+
# Returns version string from program_name, version and release.
|
905
|
+
#
|
906
|
+
def ver
|
907
|
+
if v = version
|
908
|
+
str = "#{program_name} #{[v].join('.')}"
|
909
|
+
str << " (#{v})" if v = release
|
910
|
+
str
|
911
|
+
end
|
912
|
+
end
|
913
|
+
|
914
|
+
def warn(mesg = $!)
|
915
|
+
super("#{program_name}: #{mesg}")
|
916
|
+
end
|
917
|
+
|
918
|
+
def abort(mesg = $!)
|
919
|
+
super("#{program_name}: #{mesg}")
|
920
|
+
end
|
921
|
+
|
922
|
+
#
|
923
|
+
# Subject of #on / #on_head, #accept / #reject
|
924
|
+
#
|
925
|
+
def top
|
926
|
+
@stack[-1]
|
927
|
+
end
|
928
|
+
|
929
|
+
#
|
930
|
+
# Subject of #on_tail.
|
931
|
+
#
|
932
|
+
def base
|
933
|
+
@stack[1]
|
934
|
+
end
|
935
|
+
|
936
|
+
#
|
937
|
+
# Pushes a new List.
|
938
|
+
#
|
939
|
+
def new
|
940
|
+
@stack.push(List.new)
|
941
|
+
if block_given?
|
942
|
+
yield self
|
943
|
+
else
|
944
|
+
self
|
945
|
+
end
|
946
|
+
end
|
947
|
+
|
948
|
+
#
|
949
|
+
# Removes the last List.
|
950
|
+
#
|
951
|
+
def remove
|
952
|
+
@stack.pop
|
953
|
+
end
|
954
|
+
|
955
|
+
#
|
956
|
+
# Puts option summary into +to+ and returns +to+. Yields each line if
|
957
|
+
# a block is given.
|
958
|
+
#
|
959
|
+
# +to+:: Output destination, which must have method <<. Defaults to [].
|
960
|
+
# +width+:: Width of left side, defaults to @summary_width.
|
961
|
+
# +max+:: Maximum length allowed for left side, defaults to +width+ - 1.
|
962
|
+
# +indent+:: Indentation, defaults to @summary_indent.
|
963
|
+
#
|
964
|
+
def summarize(to = [], width = @summary_width, max = width - 1, indent = @summary_indent, &blk)
|
965
|
+
visit(:summarize, {}, {}, width, max, indent, &(blk || proc {|l| to << l + $/}))
|
966
|
+
to
|
967
|
+
end
|
968
|
+
|
969
|
+
#
|
970
|
+
# Returns option summary string.
|
971
|
+
#
|
972
|
+
def help; summarize(banner.to_s.sub(/\n?\z/, "\n")) end
|
973
|
+
alias to_s help
|
974
|
+
|
975
|
+
#
|
976
|
+
# Returns option summary list.
|
977
|
+
#
|
978
|
+
def to_a; summarize(banner.to_a.dup) end
|
979
|
+
|
980
|
+
#
|
981
|
+
# Checks if an argument is given twice, in which case an ArgumentError is
|
982
|
+
# raised. Called from OptionParser#switch only.
|
983
|
+
#
|
984
|
+
# +obj+:: New argument.
|
985
|
+
# +prv+:: Previously specified argument.
|
986
|
+
# +msg+:: Exception message.
|
987
|
+
#
|
988
|
+
def notwice(obj, prv, msg)
|
989
|
+
unless !prv or prv == obj
|
990
|
+
begin
|
991
|
+
raise ArgumentError, "argument #{msg} given twice: #{obj}"
|
992
|
+
rescue
|
993
|
+
$@[0, 2] = nil
|
994
|
+
raise
|
995
|
+
end
|
996
|
+
end
|
997
|
+
obj
|
998
|
+
end
|
999
|
+
private :notwice
|
1000
|
+
|
1001
|
+
#
|
1002
|
+
# Creates an OptionParser::Switch from the parameters. The parsed argument
|
1003
|
+
# value is passed to the given block, where it can be processed.
|
1004
|
+
#
|
1005
|
+
# See at the beginning of OptionParser for some full examples.
|
1006
|
+
#
|
1007
|
+
# +opts+ can include the following elements:
|
1008
|
+
#
|
1009
|
+
# [Argument style:]
|
1010
|
+
# One of the following:
|
1011
|
+
# :NONE, :REQUIRED, :OPTIONAL
|
1012
|
+
#
|
1013
|
+
# [Argument pattern:]
|
1014
|
+
# Acceptable option argument format, must be pre-defined with
|
1015
|
+
# OptionParser.accept or OptionParser#accept, or Regexp. This can appear
|
1016
|
+
# once or assigned as String if not present, otherwise causes an
|
1017
|
+
# ArgumentError. Examples:
|
1018
|
+
# Float, Time, Array
|
1019
|
+
#
|
1020
|
+
# [Possible argument values:]
|
1021
|
+
# Hash or Array.
|
1022
|
+
# [:text, :binary, :auto]
|
1023
|
+
# %w[iso-2022-jp shift_jis euc-jp utf8 binary]
|
1024
|
+
# { "jis" => "iso-2022-jp", "sjis" => "shift_jis" }
|
1025
|
+
#
|
1026
|
+
# [Long style switch:]
|
1027
|
+
# Specifies a long style switch which takes a mandatory, optional or no
|
1028
|
+
# argument. It's a string of the following form:
|
1029
|
+
# "--switch=MANDATORY" or "--switch MANDATORY"
|
1030
|
+
# "--switch[=OPTIONAL]"
|
1031
|
+
# "--switch"
|
1032
|
+
#
|
1033
|
+
# [Short style switch:]
|
1034
|
+
# Specifies short style switch which takes a mandatory, optional or no
|
1035
|
+
# argument. It's a string of the following form:
|
1036
|
+
# "-xMANDATORY"
|
1037
|
+
# "-x[OPTIONAL]"
|
1038
|
+
# "-x"
|
1039
|
+
# There is also a special form which matches character range (not full
|
1040
|
+
# set of regural expression):
|
1041
|
+
# "-[a-z]MANDATORY"
|
1042
|
+
# "-[a-z][OPTIONAL]"
|
1043
|
+
# "-[a-z]"
|
1044
|
+
#
|
1045
|
+
# [Argument style and description:]
|
1046
|
+
# Instead of specifying mandatory or optional orguments directly in the
|
1047
|
+
# switch parameter, this separate parameter can be used.
|
1048
|
+
# "=MANDATORY"
|
1049
|
+
# "=[OPTIONAL]"
|
1050
|
+
#
|
1051
|
+
# [Description:]
|
1052
|
+
# Description string for the option.
|
1053
|
+
# "Run verbosely"
|
1054
|
+
#
|
1055
|
+
# [Handler:]
|
1056
|
+
# Handler for the parsed argument value. Either give a block or pass a
|
1057
|
+
# Proc or Method as an argument.
|
1058
|
+
#
|
1059
|
+
def make_switch(opts, block = nil)
|
1060
|
+
short, long, nolong, style, pattern, conv, not_pattern, not_conv, not_style = [], [], []
|
1061
|
+
ldesc, sdesc, desc, arg = [], [], []
|
1062
|
+
default_style = Switch::NoArgument
|
1063
|
+
default_pattern = nil
|
1064
|
+
klass = nil
|
1065
|
+
o = nil
|
1066
|
+
n, q, a = nil
|
1067
|
+
|
1068
|
+
opts.each do |o|
|
1069
|
+
# argument class
|
1070
|
+
next if search(:atype, o) do |pat, c|
|
1071
|
+
klass = notwice(o, klass, 'type')
|
1072
|
+
if not_style and not_style != Switch::NoArgument
|
1073
|
+
not_pattern, not_conv = pat, c
|
1074
|
+
else
|
1075
|
+
default_pattern, conv = pat, c
|
1076
|
+
end
|
1077
|
+
end
|
1078
|
+
|
1079
|
+
# directly specified pattern(any object possible to match)
|
1080
|
+
if !(String === o) and o.respond_to?(:match)
|
1081
|
+
pattern = notwice(o, pattern, 'pattern')
|
1082
|
+
conv = pattern.method(:convert).to_proc if pattern.respond_to?(:convert)
|
1083
|
+
next
|
1084
|
+
end
|
1085
|
+
|
1086
|
+
# anything others
|
1087
|
+
case o
|
1088
|
+
when Proc, Method
|
1089
|
+
block = notwice(o, block, 'block')
|
1090
|
+
when Array, Hash
|
1091
|
+
case pattern
|
1092
|
+
when CompletingHash
|
1093
|
+
when nil
|
1094
|
+
pattern = CompletingHash.new
|
1095
|
+
conv = pattern.method(:convert).to_proc if pattern.respond_to?(:convert)
|
1096
|
+
else
|
1097
|
+
raise ArgumentError, "argument pattern given twice"
|
1098
|
+
end
|
1099
|
+
o.each {|(o, *v)| pattern[o] = v.fetch(0) {o}}
|
1100
|
+
when Module
|
1101
|
+
raise ArgumentError, "unsupported argument type: #{o}"
|
1102
|
+
when *ArgumentStyle.keys
|
1103
|
+
style = notwice(ArgumentStyle[o], style, 'style')
|
1104
|
+
when /^--no-([^\[\]=\s]*)(.+)?/
|
1105
|
+
q, a = $1, $2
|
1106
|
+
o = notwice(a ? Object : TrueClass, klass, 'type')
|
1107
|
+
not_pattern, not_conv = search(:atype, o) unless not_style
|
1108
|
+
not_style = (not_style || default_style).guess(arg = a) if a
|
1109
|
+
default_style = Switch::NoArgument
|
1110
|
+
default_pattern, conv = search(:atype, FalseClass) unless default_pattern
|
1111
|
+
ldesc << "--no-#{q}"
|
1112
|
+
long << 'no-' + (q = q.downcase)
|
1113
|
+
nolong << q
|
1114
|
+
when /^--\[no-\]([^\[\]=\s]*)(.+)?/
|
1115
|
+
q, a = $1, $2
|
1116
|
+
o = notwice(a ? Object : TrueClass, klass, 'type')
|
1117
|
+
if a
|
1118
|
+
default_style = default_style.guess(arg = a)
|
1119
|
+
default_pattern, conv = search(:atype, o) unless default_pattern
|
1120
|
+
end
|
1121
|
+
ldesc << "--[no-]#{q}"
|
1122
|
+
long << (o = q.downcase)
|
1123
|
+
not_pattern, not_conv = search(:atype, FalseClass) unless not_style
|
1124
|
+
not_style = Switch::NoArgument
|
1125
|
+
nolong << 'no-' + o
|
1126
|
+
when /^--([^\[\]=\s]*)(.+)?/
|
1127
|
+
q, a = $1, $2
|
1128
|
+
if a
|
1129
|
+
o = notwice(NilClass, klass, 'type')
|
1130
|
+
default_style = default_style.guess(arg = a)
|
1131
|
+
default_pattern, conv = search(:atype, o) unless default_pattern
|
1132
|
+
end
|
1133
|
+
ldesc << "--#{q}"
|
1134
|
+
long << (o = q.downcase)
|
1135
|
+
when /^-(\[\^?\]?(?:[^\\\]]|\\.)*\])(.+)?/
|
1136
|
+
q, a = $1, $2
|
1137
|
+
o = notwice(Object, klass, 'type')
|
1138
|
+
if a
|
1139
|
+
default_style = default_style.guess(arg = a)
|
1140
|
+
default_pattern, conv = search(:atype, o) unless default_pattern
|
1141
|
+
end
|
1142
|
+
sdesc << "-#{q}"
|
1143
|
+
short << Regexp.new(q)
|
1144
|
+
when /^-(.)(.+)?/
|
1145
|
+
q, a = $1, $2
|
1146
|
+
if a
|
1147
|
+
o = notwice(NilClass, klass, 'type')
|
1148
|
+
default_style = default_style.guess(arg = a)
|
1149
|
+
default_pattern, conv = search(:atype, o) unless default_pattern
|
1150
|
+
end
|
1151
|
+
sdesc << "-#{q}"
|
1152
|
+
short << q
|
1153
|
+
when /^=/
|
1154
|
+
style = notwice(default_style.guess(arg = o), style, 'style')
|
1155
|
+
default_pattern, conv = search(:atype, Object) unless default_pattern
|
1156
|
+
else
|
1157
|
+
desc.push(o)
|
1158
|
+
end
|
1159
|
+
end
|
1160
|
+
|
1161
|
+
default_pattern, conv = search(:atype, default_style.pattern) unless default_pattern
|
1162
|
+
if !(short.empty? and long.empty?)
|
1163
|
+
s = (style || default_style).new(pattern || default_pattern,
|
1164
|
+
conv, sdesc, ldesc, arg, desc, block)
|
1165
|
+
elsif !block
|
1166
|
+
raise ArgumentError, "no switch given" if style or pattern
|
1167
|
+
s = desc
|
1168
|
+
else
|
1169
|
+
short << pattern
|
1170
|
+
s = (style || default_style).new(pattern,
|
1171
|
+
conv, nil, nil, arg, desc, block)
|
1172
|
+
end
|
1173
|
+
return s, short, long,
|
1174
|
+
(not_style.new(not_pattern, not_conv, sdesc, ldesc, nil, desc, block) if not_style),
|
1175
|
+
nolong
|
1176
|
+
end
|
1177
|
+
|
1178
|
+
def define(*opts, &block)
|
1179
|
+
top.append(*(sw = make_switch(opts, block)))
|
1180
|
+
sw[0]
|
1181
|
+
end
|
1182
|
+
|
1183
|
+
#
|
1184
|
+
# Add option switch and handler. See #make_switch for an explanation of
|
1185
|
+
# parameters.
|
1186
|
+
#
|
1187
|
+
def on(*opts, &block)
|
1188
|
+
define(*opts, &block)
|
1189
|
+
self
|
1190
|
+
end
|
1191
|
+
alias def_option define
|
1192
|
+
|
1193
|
+
def define_head(*opts, &block)
|
1194
|
+
top.prepend(*(sw = make_switch(opts, block)))
|
1195
|
+
sw[0]
|
1196
|
+
end
|
1197
|
+
|
1198
|
+
#
|
1199
|
+
# Add option switch like with #on, but at head of summary.
|
1200
|
+
#
|
1201
|
+
def on_head(*opts, &block)
|
1202
|
+
define_head(*opts, &block)
|
1203
|
+
self
|
1204
|
+
end
|
1205
|
+
alias def_head_option define_head
|
1206
|
+
|
1207
|
+
def define_tail(*opts, &block)
|
1208
|
+
base.append(*(sw = make_switch(opts, block)))
|
1209
|
+
sw[0]
|
1210
|
+
end
|
1211
|
+
|
1212
|
+
#
|
1213
|
+
# Add option switch like with #on, but at tail of summary.
|
1214
|
+
#
|
1215
|
+
def on_tail(*opts, &block)
|
1216
|
+
define_tail(*opts, &block)
|
1217
|
+
self
|
1218
|
+
end
|
1219
|
+
alias def_tail_option define_tail
|
1220
|
+
|
1221
|
+
#
|
1222
|
+
# Add separator in summary.
|
1223
|
+
#
|
1224
|
+
def separator(string)
|
1225
|
+
top.append(string, nil, nil)
|
1226
|
+
end
|
1227
|
+
|
1228
|
+
#
|
1229
|
+
# Parses command line arguments +argv+ in order. When a block is given,
|
1230
|
+
# each non-option argument is yielded.
|
1231
|
+
#
|
1232
|
+
# Returns the rest of +argv+ left unparsed.
|
1233
|
+
#
|
1234
|
+
def order(*argv, &block)
|
1235
|
+
argv = argv[0].dup if argv.size == 1 and Array === argv[0]
|
1236
|
+
order!(argv, &block)
|
1237
|
+
end
|
1238
|
+
|
1239
|
+
#
|
1240
|
+
# Same as #order, but removes switches destructively.
|
1241
|
+
#
|
1242
|
+
def order!(argv = default_argv, &nonopt)
|
1243
|
+
parse_in_order(argv, &nonopt)
|
1244
|
+
end
|
1245
|
+
|
1246
|
+
def parse_in_order(argv = default_argv, setter = nil, &nonopt) # :nodoc:
|
1247
|
+
opt, arg, sw, val, rest = nil
|
1248
|
+
nonopt ||= proc {|arg| throw :terminate, arg}
|
1249
|
+
argv.unshift(arg) if arg = catch(:terminate) {
|
1250
|
+
while arg = argv.shift
|
1251
|
+
case arg
|
1252
|
+
# long option
|
1253
|
+
when /\A--([^=]*)(?:=(.*))?/nm
|
1254
|
+
opt, rest = $1, $2
|
1255
|
+
begin
|
1256
|
+
sw, = complete(:long, opt, true)
|
1257
|
+
rescue ParseError
|
1258
|
+
raise $!.set_option(arg, true)
|
1259
|
+
end
|
1260
|
+
begin
|
1261
|
+
opt, cb, val = sw.parse(rest, argv) {|*exc| raise(*exc)}
|
1262
|
+
val = cb.call(val) if cb
|
1263
|
+
setter.call(sw.switch_name, val) if setter
|
1264
|
+
rescue ParseError
|
1265
|
+
raise $!.set_option(arg, rest)
|
1266
|
+
end
|
1267
|
+
|
1268
|
+
# short option
|
1269
|
+
when /\A-(.)((=).*|.+)?/nm
|
1270
|
+
opt, has_arg, eq, val, rest = $1, $3, $3, $2, $2
|
1271
|
+
begin
|
1272
|
+
sw, = search(:short, opt)
|
1273
|
+
unless sw
|
1274
|
+
begin
|
1275
|
+
sw, = complete(:short, opt)
|
1276
|
+
# short option matched.
|
1277
|
+
val = arg.sub(/\A-/, '')
|
1278
|
+
has_arg = true
|
1279
|
+
rescue InvalidOption
|
1280
|
+
# if no short options match, try completion with long
|
1281
|
+
# options.
|
1282
|
+
sw, = complete(:long, opt)
|
1283
|
+
eq ||= !rest
|
1284
|
+
end
|
1285
|
+
end
|
1286
|
+
rescue ParseError
|
1287
|
+
raise $!.set_option(arg, true)
|
1288
|
+
end
|
1289
|
+
begin
|
1290
|
+
opt, cb, val = sw.parse(val, argv) {|*exc| raise(*exc) if eq}
|
1291
|
+
raise InvalidOption, arg if has_arg and !eq and arg == "-#{opt}"
|
1292
|
+
argv.unshift(opt) if opt and (opt = opt.sub(/\A-*/, '-')) != '-'
|
1293
|
+
val = cb.call(val) if cb
|
1294
|
+
setter.call(sw.switch_name, val) if setter
|
1295
|
+
rescue ParseError
|
1296
|
+
raise $!.set_option(arg, arg.length > 2)
|
1297
|
+
end
|
1298
|
+
|
1299
|
+
# non-option argument
|
1300
|
+
else
|
1301
|
+
catch(:prune) do
|
1302
|
+
visit(:each_option) do |sw|
|
1303
|
+
sw.block.call(arg) if Switch === sw and sw.match_nonswitch?(arg)
|
1304
|
+
end
|
1305
|
+
nonopt.call(arg)
|
1306
|
+
end
|
1307
|
+
end
|
1308
|
+
end
|
1309
|
+
|
1310
|
+
nil
|
1311
|
+
}
|
1312
|
+
|
1313
|
+
visit(:search, :short, nil) {|sw| sw.block.call(*argv) if !sw.pattern}
|
1314
|
+
|
1315
|
+
argv
|
1316
|
+
end
|
1317
|
+
private :parse_in_order
|
1318
|
+
|
1319
|
+
#
|
1320
|
+
# Parses command line arguments +argv+ in permutation mode and returns
|
1321
|
+
# list of non-option arguments.
|
1322
|
+
#
|
1323
|
+
def permute(*argv)
|
1324
|
+
argv = argv[0].dup if argv.size == 1 and Array === argv[0]
|
1325
|
+
permute!(argv)
|
1326
|
+
end
|
1327
|
+
|
1328
|
+
#
|
1329
|
+
# Same as #permute, but removes switches destructively.
|
1330
|
+
#
|
1331
|
+
def permute!(argv = default_argv)
|
1332
|
+
nonopts = []
|
1333
|
+
arg = nil
|
1334
|
+
order!(argv) {|arg| nonopts << arg}
|
1335
|
+
argv[0, 0] = nonopts
|
1336
|
+
argv
|
1337
|
+
end
|
1338
|
+
|
1339
|
+
#
|
1340
|
+
# Parses command line arguments +argv+ in order when environment variable
|
1341
|
+
# POSIXLY_CORRECT is set, and in permutation mode otherwise.
|
1342
|
+
#
|
1343
|
+
def parse(*argv)
|
1344
|
+
argv = argv[0].dup if argv.size == 1 and Array === argv[0]
|
1345
|
+
parse!(argv)
|
1346
|
+
end
|
1347
|
+
|
1348
|
+
#
|
1349
|
+
# Same as #parse, but removes switches destructively.
|
1350
|
+
#
|
1351
|
+
def parse!(argv = default_argv)
|
1352
|
+
if ENV.include?('POSIXLY_CORRECT')
|
1353
|
+
order!(argv)
|
1354
|
+
else
|
1355
|
+
permute!(argv)
|
1356
|
+
end
|
1357
|
+
end
|
1358
|
+
|
1359
|
+
#
|
1360
|
+
# Wrapper method for getopts.rb.
|
1361
|
+
#
|
1362
|
+
# params = ARGV.getopts("ab:", "foo", "bar:")
|
1363
|
+
# # params[:a] = true # -a
|
1364
|
+
# # params[:b] = "1" # -b1
|
1365
|
+
# # params[:foo] = "1" # --foo
|
1366
|
+
# # params[:bar] = "x" # --bar x
|
1367
|
+
#
|
1368
|
+
def getopts(*args)
|
1369
|
+
argv = Array === args.first ? args.shift : default_argv
|
1370
|
+
single_options, *long_options = *args
|
1371
|
+
|
1372
|
+
result = {}
|
1373
|
+
|
1374
|
+
single_options.scan(/(.)(:)?/) do |opt, val|
|
1375
|
+
if val
|
1376
|
+
result[opt] = nil
|
1377
|
+
define("-#{opt} VAL")
|
1378
|
+
else
|
1379
|
+
result[opt] = false
|
1380
|
+
define("-#{opt}")
|
1381
|
+
end
|
1382
|
+
end if single_options
|
1383
|
+
|
1384
|
+
long_options.each do |arg|
|
1385
|
+
opt, val = arg.split(':', 2)
|
1386
|
+
if val
|
1387
|
+
result[opt] = val.empty? ? nil : val
|
1388
|
+
define("--#{opt} VAL")
|
1389
|
+
else
|
1390
|
+
result[opt] = false
|
1391
|
+
define("--#{opt}")
|
1392
|
+
end
|
1393
|
+
end
|
1394
|
+
|
1395
|
+
parse_in_order(argv, result.method(:[]=))
|
1396
|
+
result
|
1397
|
+
end
|
1398
|
+
|
1399
|
+
#
|
1400
|
+
# See #getopts.
|
1401
|
+
#
|
1402
|
+
def self.getopts(*args)
|
1403
|
+
new.getopts(*args)
|
1404
|
+
end
|
1405
|
+
|
1406
|
+
#
|
1407
|
+
# Traverses @stack, sending each element method +id+ with +args+ and
|
1408
|
+
# +block+.
|
1409
|
+
#
|
1410
|
+
def visit(id, *args, &block)
|
1411
|
+
el = nil
|
1412
|
+
@stack.reverse_each do |el|
|
1413
|
+
el.send(id, *args, &block)
|
1414
|
+
end
|
1415
|
+
nil
|
1416
|
+
end
|
1417
|
+
private :visit
|
1418
|
+
|
1419
|
+
#
|
1420
|
+
# Searches +key+ in @stack for +id+ hash and returns or yields the result.
|
1421
|
+
#
|
1422
|
+
def search(id, key)
|
1423
|
+
block_given = block_given?
|
1424
|
+
visit(:search, id, key) do |k|
|
1425
|
+
return block_given ? yield(k) : k
|
1426
|
+
end
|
1427
|
+
end
|
1428
|
+
private :search
|
1429
|
+
|
1430
|
+
#
|
1431
|
+
# Completes shortened long style option switch and returns pair of
|
1432
|
+
# canonical switch and switch descriptor OptionParser::Switch.
|
1433
|
+
#
|
1434
|
+
# +id+:: Searching table.
|
1435
|
+
# +opt+:: Searching key.
|
1436
|
+
# +icase+:: Search case insensitive if true.
|
1437
|
+
# +pat+:: Optional pattern for completion.
|
1438
|
+
#
|
1439
|
+
def complete(typ, opt, icase = false, *pat)
|
1440
|
+
if pat.empty?
|
1441
|
+
search(typ, opt) {|sw| return [sw, opt]} # exact match or...
|
1442
|
+
end
|
1443
|
+
raise AmbiguousOption, catch(:ambiguous) {
|
1444
|
+
visit(:complete, typ, opt, icase, *pat) {|opt, *sw| return sw}
|
1445
|
+
raise InvalidOption, opt
|
1446
|
+
}
|
1447
|
+
end
|
1448
|
+
private :complete
|
1449
|
+
|
1450
|
+
#
|
1451
|
+
# Loads options from file names as +filename+. Does nothing when the file
|
1452
|
+
# is not present. Returns whether successfully loaded.
|
1453
|
+
#
|
1454
|
+
# +filename+ defaults to basename of the program without suffix in a
|
1455
|
+
# directory ~/.options.
|
1456
|
+
#
|
1457
|
+
def load(filename = nil)
|
1458
|
+
begin
|
1459
|
+
filename ||= File.expand_path(File.basename($0, '.*'), '~/.options')
|
1460
|
+
rescue
|
1461
|
+
return false
|
1462
|
+
end
|
1463
|
+
begin
|
1464
|
+
parse(*IO.readlines(filename).each {|s| s.chomp!})
|
1465
|
+
true
|
1466
|
+
rescue Errno::ENOENT, Errno::ENOTDIR
|
1467
|
+
false
|
1468
|
+
end
|
1469
|
+
end
|
1470
|
+
|
1471
|
+
#
|
1472
|
+
# Parses environment variable +env+ or its uppercase with splitting like a
|
1473
|
+
# shell.
|
1474
|
+
#
|
1475
|
+
# +env+ defaults to the basename of the program.
|
1476
|
+
#
|
1477
|
+
def environment(env = File.basename($0, '.*'))
|
1478
|
+
env = ENV[env] || ENV[env.upcase] or return
|
1479
|
+
parse(*Shellwords.shellwords(env))
|
1480
|
+
end
|
1481
|
+
|
1482
|
+
#
|
1483
|
+
# Acceptable argument classes
|
1484
|
+
#
|
1485
|
+
|
1486
|
+
#
|
1487
|
+
# Any string and no conversion. This is fall-back.
|
1488
|
+
#
|
1489
|
+
accept(Object) {|s,|s or s.nil?}
|
1490
|
+
|
1491
|
+
accept(NilClass) {|s,|s}
|
1492
|
+
|
1493
|
+
#
|
1494
|
+
# Any non-empty string, and no conversion.
|
1495
|
+
#
|
1496
|
+
accept(String, /.+/nm) {|s,*|s}
|
1497
|
+
|
1498
|
+
#
|
1499
|
+
# Ruby/C-like integer, octal for 0-7 sequence, binary for 0b, hexadecimal
|
1500
|
+
# for 0x, and decimal for others; with optional sign prefix. Converts to
|
1501
|
+
# Integer.
|
1502
|
+
#
|
1503
|
+
decimal = '\d+(?:_\d+)*'
|
1504
|
+
binary = 'b[01]+(?:_[01]+)*'
|
1505
|
+
hex = 'x[\da-f]+(?:_[\da-f]+)*'
|
1506
|
+
octal = "0(?:[0-7]*(?:_[0-7]+)*|#{binary}|#{hex})"
|
1507
|
+
integer = "#{octal}|#{decimal}"
|
1508
|
+
accept(Integer, %r"\A[-+]?(?:#{integer})"io) {|s,| Integer(s) if s}
|
1509
|
+
|
1510
|
+
#
|
1511
|
+
# Float number format, and converts to Float.
|
1512
|
+
#
|
1513
|
+
float = "(?:#{decimal}(?:\\.(?:#{decimal})?)?|\\.#{decimal})(?:E[-+]?#{decimal})?"
|
1514
|
+
floatpat = %r"\A[-+]?#{float}"io
|
1515
|
+
accept(Float, floatpat) {|s,| s.to_f if s}
|
1516
|
+
|
1517
|
+
#
|
1518
|
+
# Generic numeric format, converts to Integer for integer format, Float
|
1519
|
+
# for float format.
|
1520
|
+
#
|
1521
|
+
accept(Numeric, %r"\A[-+]?(?:#{octal}|#{float})"io) {|s,| eval(s) if s}
|
1522
|
+
|
1523
|
+
#
|
1524
|
+
# Decimal integer format, to be converted to Integer.
|
1525
|
+
#
|
1526
|
+
DecimalInteger = /\A[-+]?#{decimal}/io
|
1527
|
+
accept(DecimalInteger) {|s,| s.to_i if s}
|
1528
|
+
|
1529
|
+
#
|
1530
|
+
# Ruby/C like octal/hexadecimal/binary integer format, to be converted to
|
1531
|
+
# Integer.
|
1532
|
+
#
|
1533
|
+
OctalInteger = /\A[-+]?(?:[0-7]+(?:_[0-7]+)*|0(?:#{binary}|#{hex}))/io
|
1534
|
+
accept(OctalInteger) {|s,| s.oct if s}
|
1535
|
+
|
1536
|
+
#
|
1537
|
+
# Decimal integer/float number format, to be converted to Integer for
|
1538
|
+
# integer format, Float for float format.
|
1539
|
+
#
|
1540
|
+
DecimalNumeric = floatpat # decimal integer is allowed as float also.
|
1541
|
+
accept(DecimalNumeric) {|s,| eval(s) if s}
|
1542
|
+
|
1543
|
+
#
|
1544
|
+
# Boolean switch, which means whether it is present or not, whether it is
|
1545
|
+
# absent or not with prefix no-, or it takes an argument
|
1546
|
+
# yes/no/true/false/+/-.
|
1547
|
+
#
|
1548
|
+
yesno = CompletingHash.new
|
1549
|
+
%w[- no false].each {|el| yesno[el] = false}
|
1550
|
+
%w[+ yes true].each {|el| yesno[el] = true}
|
1551
|
+
yesno['nil'] = false # shoud be nil?
|
1552
|
+
accept(TrueClass, yesno) {|arg, val| val == nil or val}
|
1553
|
+
#
|
1554
|
+
# Similar to TrueClass, but defaults to false.
|
1555
|
+
#
|
1556
|
+
accept(FalseClass, yesno) {|arg, val| val != nil and val}
|
1557
|
+
|
1558
|
+
#
|
1559
|
+
# List of strings separated by ",".
|
1560
|
+
#
|
1561
|
+
accept(Array) do |s,|
|
1562
|
+
if s
|
1563
|
+
s = s.split(',').collect {|s| s unless s.empty?}
|
1564
|
+
end
|
1565
|
+
s
|
1566
|
+
end
|
1567
|
+
|
1568
|
+
#
|
1569
|
+
# Regular expression with options.
|
1570
|
+
#
|
1571
|
+
accept(Regexp, %r"\A/((?:\\.|[^\\])*)/([[:alpha:]]+)?\z|.*") do |all, s, o|
|
1572
|
+
f = 0
|
1573
|
+
if o
|
1574
|
+
f |= Regexp::IGNORECASE if /i/ =~ o
|
1575
|
+
f |= Regexp::MULTILINE if /m/ =~ o
|
1576
|
+
f |= Regexp::EXTENDED if /x/ =~ o
|
1577
|
+
k = o.delete("^imx")
|
1578
|
+
end
|
1579
|
+
Regexp.new(s || all, f, k)
|
1580
|
+
end
|
1581
|
+
|
1582
|
+
#
|
1583
|
+
# Exceptions
|
1584
|
+
#
|
1585
|
+
|
1586
|
+
#
|
1587
|
+
# Base class of exceptions from OptionParser.
|
1588
|
+
#
|
1589
|
+
class ParseError < RuntimeError
|
1590
|
+
# Reason which caused the error.
|
1591
|
+
Reason = 'parse error'.freeze
|
1592
|
+
|
1593
|
+
def initialize(*args)
|
1594
|
+
@args = args
|
1595
|
+
@reason = nil
|
1596
|
+
end
|
1597
|
+
|
1598
|
+
attr_reader :args
|
1599
|
+
attr_writer :reason
|
1600
|
+
|
1601
|
+
#
|
1602
|
+
# Pushes back erred argument(s) to +argv+.
|
1603
|
+
#
|
1604
|
+
def recover(argv)
|
1605
|
+
argv[0, 0] = @args
|
1606
|
+
argv
|
1607
|
+
end
|
1608
|
+
|
1609
|
+
def set_option(opt, eq)
|
1610
|
+
if eq
|
1611
|
+
@args[0] = opt
|
1612
|
+
else
|
1613
|
+
@args.unshift(opt)
|
1614
|
+
end
|
1615
|
+
self
|
1616
|
+
end
|
1617
|
+
|
1618
|
+
#
|
1619
|
+
# Returns error reason. Override this for I18N.
|
1620
|
+
#
|
1621
|
+
def reason
|
1622
|
+
@reason || self.class::Reason
|
1623
|
+
end
|
1624
|
+
|
1625
|
+
def inspect
|
1626
|
+
"#<#{self.class.to_s}: #{args.join(' ')}>"
|
1627
|
+
end
|
1628
|
+
|
1629
|
+
#
|
1630
|
+
# Default stringizing method to emit standard error message.
|
1631
|
+
#
|
1632
|
+
def message
|
1633
|
+
reason + ': ' + args.join(' ')
|
1634
|
+
end
|
1635
|
+
|
1636
|
+
alias to_s message
|
1637
|
+
end
|
1638
|
+
|
1639
|
+
#
|
1640
|
+
# Raises when ambiguously completable string is encountered.
|
1641
|
+
#
|
1642
|
+
class AmbiguousOption < ParseError
|
1643
|
+
const_set(:Reason, 'ambiguous option'.freeze)
|
1644
|
+
end
|
1645
|
+
|
1646
|
+
#
|
1647
|
+
# Raises when there is an argument for a switch which takes no argument.
|
1648
|
+
#
|
1649
|
+
class NeedlessArgument < ParseError
|
1650
|
+
const_set(:Reason, 'needless argument'.freeze)
|
1651
|
+
end
|
1652
|
+
|
1653
|
+
#
|
1654
|
+
# Raises when a switch with mandatory argument has no argument.
|
1655
|
+
#
|
1656
|
+
class MissingArgument < ParseError
|
1657
|
+
const_set(:Reason, 'missing argument'.freeze)
|
1658
|
+
end
|
1659
|
+
|
1660
|
+
#
|
1661
|
+
# Raises when switch is undefined.
|
1662
|
+
#
|
1663
|
+
class InvalidOption < ParseError
|
1664
|
+
const_set(:Reason, 'invalid option'.freeze)
|
1665
|
+
end
|
1666
|
+
|
1667
|
+
#
|
1668
|
+
# Raises when the given argument does not match required format.
|
1669
|
+
#
|
1670
|
+
class InvalidArgument < ParseError
|
1671
|
+
const_set(:Reason, 'invalid argument'.freeze)
|
1672
|
+
end
|
1673
|
+
|
1674
|
+
#
|
1675
|
+
# Raises when the given argument word can't be completed uniquely.
|
1676
|
+
#
|
1677
|
+
class AmbiguousArgument < InvalidArgument
|
1678
|
+
const_set(:Reason, 'ambiguous argument'.freeze)
|
1679
|
+
end
|
1680
|
+
|
1681
|
+
#
|
1682
|
+
# Miscellaneous
|
1683
|
+
#
|
1684
|
+
|
1685
|
+
#
|
1686
|
+
# Extends command line arguments array (ARGV) to parse itself.
|
1687
|
+
#
|
1688
|
+
module Arguable
|
1689
|
+
|
1690
|
+
#
|
1691
|
+
# Sets OptionParser object, when +opt+ is +false+ or +nil+, methods
|
1692
|
+
# OptionParser::Arguable#options and OptionParser::Arguable#options= are
|
1693
|
+
# undefined. Thus, there is no ways to access the OptionParser object
|
1694
|
+
# via the receiver object.
|
1695
|
+
#
|
1696
|
+
def options=(opt)
|
1697
|
+
unless @optparse = opt
|
1698
|
+
class << self
|
1699
|
+
undef_method(:options)
|
1700
|
+
undef_method(:options=)
|
1701
|
+
end
|
1702
|
+
end
|
1703
|
+
end
|
1704
|
+
|
1705
|
+
#
|
1706
|
+
# Actual OptionParser object, automatically created if nonexistent.
|
1707
|
+
#
|
1708
|
+
# If called with a block, yields the OptionParser object and returns the
|
1709
|
+
# result of the block. If an OptionParser::ParseError exception occurs
|
1710
|
+
# in the block, it is rescued, a error message printed to STDERR and
|
1711
|
+
# +nil+ returned.
|
1712
|
+
#
|
1713
|
+
def options
|
1714
|
+
@optparse ||= OptionParser.new
|
1715
|
+
@optparse.default_argv = self
|
1716
|
+
block_given? or return @optparse
|
1717
|
+
begin
|
1718
|
+
yield @optparse
|
1719
|
+
rescue ParseError
|
1720
|
+
@optparse.warn $!
|
1721
|
+
nil
|
1722
|
+
end
|
1723
|
+
end
|
1724
|
+
|
1725
|
+
#
|
1726
|
+
# Parses +self+ destructively in order and returns +self+ containing the
|
1727
|
+
# rest arguments left unparsed.
|
1728
|
+
#
|
1729
|
+
def order!(&blk) options.order!(self, &blk) end
|
1730
|
+
|
1731
|
+
#
|
1732
|
+
# Parses +self+ destructively in permutation mode and returns +self+
|
1733
|
+
# containing the rest arguments left unparsed.
|
1734
|
+
#
|
1735
|
+
def permute!() options.permute!(self) end
|
1736
|
+
|
1737
|
+
#
|
1738
|
+
# Parses +self+ destructively and returns +self+ containing the
|
1739
|
+
# rest arguments left unparsed.
|
1740
|
+
#
|
1741
|
+
def parse!() options.parse!(self) end
|
1742
|
+
|
1743
|
+
#
|
1744
|
+
# Substitution of getopts is possible as follows. Also see
|
1745
|
+
# OptionParser#getopts.
|
1746
|
+
#
|
1747
|
+
# def getopts(*args)
|
1748
|
+
# ($OPT = ARGV.getopts(*args)).each do |opt, val|
|
1749
|
+
# eval "$OPT_#{opt.gsub(/[^A-Za-z0-9_]/, '_')} = val"
|
1750
|
+
# end
|
1751
|
+
# rescue OptionParser::ParseError
|
1752
|
+
# end
|
1753
|
+
#
|
1754
|
+
def getopts(*args)
|
1755
|
+
options.getopts(self, *args)
|
1756
|
+
end
|
1757
|
+
|
1758
|
+
#
|
1759
|
+
# Initializes instance variable.
|
1760
|
+
#
|
1761
|
+
def self.extend_object(obj)
|
1762
|
+
super
|
1763
|
+
obj.instance_eval {@optparse = nil}
|
1764
|
+
end
|
1765
|
+
def initialize(*args)
|
1766
|
+
super
|
1767
|
+
@optparse = nil
|
1768
|
+
end
|
1769
|
+
end
|
1770
|
+
|
1771
|
+
#
|
1772
|
+
# Acceptable argument classes. Now contains DecimalInteger, OctalInteger
|
1773
|
+
# and DecimalNumeric. See Acceptable argument classes (in source code).
|
1774
|
+
#
|
1775
|
+
module Acceptables
|
1776
|
+
const_set(:DecimalInteger, OptionParser::DecimalInteger)
|
1777
|
+
const_set(:OctalInteger, OptionParser::OctalInteger)
|
1778
|
+
const_set(:DecimalNumeric, OptionParser::DecimalNumeric)
|
1779
|
+
end
|
1780
|
+
end
|
1781
|
+
|
1782
|
+
# ARGV is arguable by OptionParser
|
1783
|
+
ARGV.extend(OptionParser::Arguable)
|
1784
|
+
|
1785
|
+
if $0 == __FILE__
|
1786
|
+
Version = OptionParser::Version
|
1787
|
+
ARGV.options {|q|
|
1788
|
+
q.parse!.empty? or puts "what's #{ARGV.join(' ')}?"
|
1789
|
+
} or abort(ARGV.options.to_s)
|
1790
|
+
end
|