Method: Merb::Config.parse_args
- Defined in:
- lib/merb-core/config.rb
.parse_args(argv = ARGV) ⇒ Object
Parses the command line arguments and stores them in the config.
Parameters
- argv<String>
-
The command line arguments. Defaults to
ARGV.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
# File 'lib/merb-core/config.rb', line 118 def parse_args(argv = ARGV) @configuration ||= {} # Our primary configuration hash for the length of this method = {} # Environment variables always win [:environment] = ENV["MERB_ENV"] if ENV["MERB_ENV"] # Build a parser for the command line arguments opts = OptionParser.new do |opts| opts.version = Merb::VERSION opts. = "Usage: merb [uGdcIpPhmailLerkKX] [argument]" opts.define_head "Merb. Pocket rocket web framework" opts.separator '*' * 80 opts.separator "If no flags are given, Merb starts in the " \ "foreground on port 4000." opts.separator '*' * 80 opts.on("-u", "--user USER", "This flag is for having merb run " \ "as a user other than the one currently logged in. Note: " \ "if you set this you must also provide a --group option " \ "for it to take effect.") do |user| [:user] = user end opts.on("-G", "--group GROUP", "This flag is for having merb run " \ "as a group other than the one currently logged in. Note: " \ "if you set this you must also provide a --user option " \ "for it to take effect.") do |group| [:group] = group end opts.on("-d", "--daemonize", "This will run a single merb in the " \ "background.") do |daemon| [:daemonize] = true end opts.on("-N", "--no-daemonize", "This will allow you to run a " \ "cluster in console mode") do |no_daemon| [:daemonize] = false end opts.on("-c", "--cluster-nodes NUM_MERBS", Integer, "Number of merb daemons to run.") do |nodes| [:daemonize] = true unless .key?(:daemonize) [:cluster] = nodes end opts.on("-I", "--init-file FILE", "File to use for initialization " \ "on load, defaults to config/init.rb") do |init_file| [:init_file] = init_file end opts.on("-p", "--port PORTNUM", Integer, "Port to run merb on, " \ "defaults to 4000.") do |port| [:port] = port end opts.on("-o", "--socket-file FILE", "Socket file to run merb on, " \ "defaults to [Merb.root]/log/merb.sock. This is for " \ "web servers, like thin, that use sockets.") do |port| [:socket_file] = port end opts.on("-s", "--socket SOCKNUM", Integer, "Socket number to run " \ "merb on, defaults to 0.") do |port| [:socket] = port end opts.on("-P", "--pid PIDFILE", "PID file, defaults to " \ "[Merb.root]/log/merb.main.pid for the master process and" \ "[Merb.root]/log/merb.[port number].pid for worker " \ "processes. For clusters, use %s to specify where " \ "in the file merb should place the port number. For " \ "instance: -P myapp.%s.pid") do |pid_file| [:pid_file] = pid_file end opts.on("-h", "--host HOSTNAME", "Host to bind to " \ "(default is 0.0.0.0).") do |host| [:host] = host end opts.on("-m", "--merb-root /path/to/approot", "The path to the " \ "Merb.root for the app you want to run " \ "(default is current working directory).") do |root| [:merb_root] = File.(root) end adapters = [:mongrel, :emongrel, :thin, :ebb, :fastcgi, :webrick] opts.on("-a", "--adapter ADAPTER", "The rack adapter to use to run merb (default is mongrel)" \ "[#{adapters.join(', ')}]") do |adapter| [:adapter] ||= adapter end opts.on("-R", "--rackup FILE", "Load an alternate Rack config " \ "file (default is config/rack.rb)") do |rackup| [:rackup] = rackup end opts.on("-i", "--irb-console", "This flag will start merb in " \ "irb console mode. All your models and other classes will " \ "be available for you in an irb session.") do |console| [:adapter] = 'irb' end opts.on("-S", "--sandbox", "This flag will enable a sandboxed irb " \ "console. If your ORM supports transactions, all edits will " \ "be rolled back on exit.") do |sandbox| [:sandbox] = true end opts.on("-l", "--log-level LEVEL", "Log levels can be set to any of " \ "these options: debug < info < warn < error < " \ "fatal (default is info)") do |log_level| [:log_level] = log_level.to_sym [:force_logging] = true end opts.on("-L", "--log LOGFILE", "A string representing the logfile to " \ "use. Defaults to [Merb.root]/log/merb.[main].log for the " \ "master process and [Merb.root]/log/merb[port number].log" \ "for worker processes") do |log_file| [:log_file] = log_file [:force_logging] = true end opts.on("-e", "--environment STRING", "Environment to run Merb " \ "under [development, production, testing] " \ "(default is development)") do |env| [:environment] = env end opts.on("-r", "--script-runner ['RUBY CODE'| FULL_SCRIPT_PATH]", "Command-line option to run scripts and/or code in the " \ "merb app.") do |code_or_file| [:runner_code] = code_or_file [:adapter] = 'runner' end opts.on("-K", "--graceful PORT or all", "Gracefully kill one " \ "merb proceses by port number. Use merb -K all to " \ "gracefully kill all merbs.") do |ports| [:action] = :kill ports = "main" if ports == "all" [:port] = ports end opts.on("-k", "--kill PORT", "Force kill one merb worker " \ "by port number. This will cause the worker to" \ "be respawned. If you want to kill ") do |port| [:action] = :kill_9 port = "main" if port == "all" [:port] = port end opts.on("--fast-deploy", "Reload the code, but not your" \ "init.rb or gems") do [:action] = :fast_deploy end # @todo Do we really need this flag? It seems unlikely to want to # change the mutex from the command-line. opts.on("-X", "--mutex on/off", "This flag is for turning the " \ "mutex lock on and off.") do |mutex| if mutex == "off" [:use_mutex] = false else [:use_mutex] = true end end opts.on("-D", "--debugger", "Run merb using rDebug.") do begin require "ruby-debug" Debugger.start if Debugger.respond_to?(:settings) Debugger.settings[:autoeval] = true end puts "Debugger enabled" rescue LoadError puts "You need to install ruby-debug to run the server in " \ "debugging mode. With gems, use `gem install ruby-debug'" exit end end opts.on("-V", "--verbose", "Print extra information") do [:verbose] = true end opts.on("-C", "--console-trap", "Enter an irb console on ^C") do [:console_trap] = true end opts.on("-?", "-H", "--help", "Show this help message") do puts opts exit end end # Parse what we have on the command line begin opts.parse!(argv) rescue OptionParser::InvalidOption => e Merb.fatal! e., e end Merb::Config.setup() end |