Class: Hatetepe::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/hatetepe/cli.rb

Instance Method Summary collapse

Instance Method Details

#startObject



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
# File 'lib/hatetepe/cli.rb', line 27

def start
  require "hatetepe/server"
  
  ENV["RACK_ENV"] = expand_env(options[:env]) || ENV["RACK_ENV"] || "development"
  $stderr << "We're in #{ENV["RACK_ENV"]}\n"
  $stderr.flush
  
  rackup = File.expand_path(options[:rackup] || "config.ru")
  $stderr << "Booting from #{rackup}\n"
  $stderr.flush
  
  app = Rack::Builder.parse_file(rackup)[0]

  EM.epoll
  EM.synchrony do
    trap("INT") { EM.stop }
    trap("TERM") { EM.stop }
    
    host = options[:bind] || "127.0.0.1"
    port = options[:port] || 3000
    
    $stderr << "Binding to #{host}:#{port}\n"
    $stderr.flush
    Server.start({
      :app => app,
      :errors => $stderr,
      :host => host,
      :port => port,
      :timeout => (options[:timeout] || 1)
    })
  end
end

#versionObject



11
12
13
14
# File 'lib/hatetepe/cli.rb', line 11

def version
  require "hatetepe/version"
  say Hatetepe::VERSION
end