Class: Rack::Server::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/server.rb

Instance Method Summary collapse

Instance Method Details

#parse!(args) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/rack/server.rb', line 6

def parse!(args)
  options = {}
  opt_parser = OptionParser.new("", 24, '  ') do |opts|
    opts.banner = "Usage: rackup [ruby options] [rack options] [rackup config]"

    opts.separator ""
    opts.separator "Ruby options:"

    lineno = 1
    opts.on("-e", "--eval LINE", "evaluate a LINE of code") { |line|
      eval line, TOPLEVEL_BINDING, "-e", lineno
      lineno += 1
    }

    opts.on("-d", "--debug", "set debugging flags (set $DEBUG to true)") {
      options[:debug] = true
    }
    opts.on("-w", "--warn", "turn warnings on for your script") {
      options[:warn] = true
    }

    opts.on("-I", "--include PATH",
            "specify $LOAD_PATH (may be used more than once)") { |path|
      options[:include] = path.split(":")
    }

    opts.on("-r", "--require LIBRARY",
            "require the library, before executing your script") { |library|
      options[:require] = library
    }

    opts.separator ""
    opts.separator "Rack options:"
    opts.on("-s", "--server SERVER", "serve using SERVER (webrick/mongrel)") { |s|
      options[:server] = s
    }

    opts.on("-o", "--host HOST", "listen on HOST (default: 0.0.0.0)") { |host|
      options[:Host] = host
    }

    opts.on("-p", "--port PORT", "use PORT (default: 9292)") { |port|
      options[:Port] = port
    }

    opts.on("-E", "--env ENVIRONMENT", "use ENVIRONMENT for defaults (default: development)") { |e|
      options[:environment] = e
    }

    opts.on("-D", "--daemonize", "run daemonized in the background") { |d|
      options[:daemonize] = d ? true : false
    }

    opts.on("-P", "--pid FILE", "file to store PID (default: rack.pid)") { |f|
      options[:pid] = f
    }

    opts.separator ""
    opts.separator "Common options:"

    opts.on_tail("-h", "-?", "--help", "Show this message") do
      puts opts
      exit
    end

    opts.on_tail("--version", "Show version") do
      puts "Rack #{Rack.version} (Release: #{Rack.release})"
      exit
    end
  end

  begin
    opt_parser.parse! args
  rescue OptionParser::InvalidOption => e
    warn e.message
    abort opt_parser.to_s
  end

  options[:config] = args.last if args.last
  options
end