Class: CodeStock::CLI_Cdweb

Inherits:
Object
  • Object
show all
Defined in:
lib/cdweb/cli_cdweb.rb

Class Method Summary collapse

Class Method Details

.execute(stdout, arguments = []) ⇒ Object



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
# File 'lib/cdweb/cli_cdweb.rb', line 13

def self.execute(stdout, arguments=[])
  option = {
    :Port => 9292,
    :DbDir => db_default_dir,
  }
  
  opt = OptionParser.new("#{File.basename($0)}")
  opt.on('--db DB_DIR', 'Database dir (default : ~/.codestock)') {|v| option[:DbDir] = v }
  opt.on('-p', '--port PORT', 'use PORT (default: 9292)') {|v| option[:Port] = v }
  opt.on('--no-browser', 'No launch browser.') {|v| option[:NoBrowser] = true }
  opt.parse!(arguments)

  # webサーバー起動
  stdout.puts <<EOF
Start up grenweb !!
URL : http://localhost:#{option[:Port]}
DB  : #{option[:DbDir]}
----------------------------------------
EOF

  # 使用するデータベースの位置設定
  Database.setup(option[:DbDir])
  
  # サーバースクリプトのある場所へ移動
  FileUtils.cd(File.dirname(__FILE__))
  
  # ブラウザ起動
  Launchy.open("http://localhost:#{option[:Port]}") unless (option[:NoBrowser])
  
  # サーバー起動
  Rack::Server.start(
                     :environment => "development",
                     :pid         => nil,
                     :Port        => option[:Port],
                     :Host        => "0.0.0.0",
                     :AccessLog   => [],
                     :config      => "grenweb.ru"
                     )

end