관리-도구
편집 파일: M000427.html
<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>parse! (Rack::Server::Options)</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" /> </head> <body class="standalone-code"> <pre><span class="ruby-comment cmt"># File lib/rack/server.rb, line 9</span> <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">parse!</span>(<span class="ruby-identifier">args</span>) <span class="ruby-identifier">options</span> = {} <span class="ruby-identifier">opt_parser</span> = <span class="ruby-constant">OptionParser</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">""</span>, <span class="ruby-value">24</span>, <span class="ruby-value str">' '</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">opts</span><span class="ruby-operator">|</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">banner</span> = <span class="ruby-value str">"Usage: rackup [ruby options] [rack options] [rackup config]"</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">""</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">"Ruby options:"</span> <span class="ruby-identifier">lineno</span> = <span class="ruby-value">1</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">"-e"</span>, <span class="ruby-value str">"--eval LINE"</span>, <span class="ruby-value str">"evaluate a LINE of code"</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">line</span><span class="ruby-operator">|</span> <span class="ruby-identifier">eval</span> <span class="ruby-identifier">line</span>, <span class="ruby-constant">TOPLEVEL_BINDING</span>, <span class="ruby-value str">"-e"</span>, <span class="ruby-identifier">lineno</span> <span class="ruby-identifier">lineno</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span> } <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">"-b"</span>, <span class="ruby-value str">"--builder BUILDER_LINE"</span>, <span class="ruby-value str">"evaluate a BUILDER_LINE of code as a builder script"</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">line</span><span class="ruby-operator">|</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:builder</span>] = <span class="ruby-identifier">line</span> } <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">"-d"</span>, <span class="ruby-value str">"--debug"</span>, <span class="ruby-value str">"set debugging flags (set $DEBUG to true)"</span>) { <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:debug</span>] = <span class="ruby-keyword kw">true</span> } <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">"-w"</span>, <span class="ruby-value str">"--warn"</span>, <span class="ruby-value str">"turn warnings on for your script"</span>) { <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:warn</span>] = <span class="ruby-keyword kw">true</span> } <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">"-q"</span>, <span class="ruby-value str">"--quiet"</span>, <span class="ruby-value str">"turn off logging"</span>) { <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:quiet</span>] = <span class="ruby-keyword kw">true</span> } <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">"-I"</span>, <span class="ruby-value str">"--include PATH"</span>, <span class="ruby-value str">"specify $LOAD_PATH (may be used more than once)"</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">path</span><span class="ruby-operator">|</span> (<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:include</span>] <span class="ruby-operator">||=</span> []).<span class="ruby-identifier">concat</span>(<span class="ruby-identifier">path</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">":"</span>)) } <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">"-r"</span>, <span class="ruby-value str">"--require LIBRARY"</span>, <span class="ruby-value str">"require the library, before executing your script"</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">library</span><span class="ruby-operator">|</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:require</span>] = <span class="ruby-identifier">library</span> } <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">""</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">"Rack options:"</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">"-s"</span>, <span class="ruby-value str">"--server SERVER"</span>, <span class="ruby-value str">"serve using SERVER (thin/puma/webrick/mongrel)"</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:server</span>] = <span class="ruby-identifier">s</span> } <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">"-o"</span>, <span class="ruby-value str">"--host HOST"</span>, <span class="ruby-value str">"listen on HOST (default: localhost)"</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">host</span><span class="ruby-operator">|</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:Host</span>] = <span class="ruby-identifier">host</span> } <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">"-p"</span>, <span class="ruby-value str">"--port PORT"</span>, <span class="ruby-value str">"use PORT (default: 9292)"</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">port</span><span class="ruby-operator">|</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:Port</span>] = <span class="ruby-identifier">port</span> } <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">"-O"</span>, <span class="ruby-value str">"--option NAME[=VALUE]"</span>, <span class="ruby-node">"pass VALUE to the server as option NAME. If no VALUE, sets it to true. Run '#{$0} -s SERVER -h' to get a list of options for SERVER"</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">name</span><span class="ruby-operator">|</span> <span class="ruby-identifier">name</span>, <span class="ruby-identifier">value</span> = <span class="ruby-identifier">name</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">'='</span>, <span class="ruby-value">2</span>) <span class="ruby-identifier">value</span> = <span class="ruby-keyword kw">true</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_sym</span>] = <span class="ruby-identifier">value</span> } <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">"-E"</span>, <span class="ruby-value str">"--env ENVIRONMENT"</span>, <span class="ruby-value str">"use ENVIRONMENT for defaults (default: development)"</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:environment</span>] = <span class="ruby-identifier">e</span> } <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">"-D"</span>, <span class="ruby-value str">"--daemonize"</span>, <span class="ruby-value str">"run daemonized in the background"</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">d</span><span class="ruby-operator">|</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:daemonize</span>] = <span class="ruby-identifier">d</span> <span class="ruby-value">? </span><span class="ruby-keyword kw">true</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">false</span> } <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">"-P"</span>, <span class="ruby-value str">"--pid FILE"</span>, <span class="ruby-value str">"file to store PID"</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:pid</span>] = <span class="ruby-operator">::</span><span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-identifier">f</span>) } <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">""</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">"Common options:"</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on_tail</span>(<span class="ruby-value str">"-h"</span>, <span class="ruby-value str">"-?"</span>, <span class="ruby-value str">"--help"</span>, <span class="ruby-value str">"Show this message"</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-identifier">puts</span> <span class="ruby-identifier">opts</span> <span class="ruby-identifier">puts</span> <span class="ruby-identifier">handler_opts</span>(<span class="ruby-identifier">options</span>) <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">end</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on_tail</span>(<span class="ruby-value str">"--version"</span>, <span class="ruby-value str">"Show version"</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-identifier">puts</span> <span class="ruby-node">"Rack #{Rack.version} (Release: #{Rack.release})"</span> <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">end</span> <span class="ruby-keyword kw">end</span> <span class="ruby-keyword kw">begin</span> <span class="ruby-identifier">opt_parser</span>.<span class="ruby-identifier">parse!</span> <span class="ruby-identifier">args</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">OptionParser</span><span class="ruby-operator">::</span><span class="ruby-constant">InvalidOption</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span> <span class="ruby-identifier">warn</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span> <span class="ruby-identifier">abort</span> <span class="ruby-identifier">opt_parser</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-keyword kw">end</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:config</span>] = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">last</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">last</span> <span class="ruby-identifier">options</span> <span class="ruby-keyword kw">end</span></pre> </body> </html>