Module: DBAdmin

Defined in:
lib/dbadmin.rb,
lib/dbadmin/app.rb

Defined Under Namespace

Classes: App

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.start(argv) ⇒ Object



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
# File 'lib/dbadmin.rb', line 12

def self.start(argv)
  options = {
    :Host => "localhost",
    :Port => 8888,
    :daemonize => true
  }
  parser = OptionParser.new do |o|
    o.on "-p", "--port PORT", "The port to run the web server on" do |arg|
      options[:Port] = arg.to_i
    end

    o.on "-h", "--host HOST", "The host to run the web server on" do |arg|
      options[:Host] = arg
    end

    o.on "-f", "--foreground", "Run server in the foreground" do |arg|
      options[:daemonize] = arg ? false : true
    end

    o.banner = "Usage: dbadmin [options] [db_url]\n\nExample: dbadmin -p 8080 mysql://user:pass@host/db\n\n"

    o.on_tail "--help", "Show help" do
      puts o
      exit 1
    end
  end

  url = parser.parse(argv).first
  ENV['DATABASE_URL'] = url if url

  puts "Starting DB Admin #{VERSION} at http://#{options[:Host]}:#{options[:Port]}"
  Rack::Server.start(options.merge(app: DBAdmin::App))
end