Class: CommandRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/yodel/command/command.rb

Class Method Summary collapse

Class Method Details

.runObject



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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/yodel/command/command.rb', line 6

def self.run
  OptionParser.new do |opts|
    opts.banner = "Usage: yodel [options] server|dns|restart|console|migrate|deploy|setup|update"
    opts.on('-p', '--port PORT', Integer, 'Override the default web server port') do |port|
      $web_port = port
    end

    opts.on('-e', '--environment ENV', 'Web server environment (default development)', 'development', 'production') do |env|
      $env = env
    end
    
    opts.on('-s', '--settings FILE', 'Load this settings file (default: /usr/local/etc/yodel/settings.rb)') do |settings|
      $settings = settings
    end
    
    opts.on('-x', '--extensions PATH', 'Load extensions from the supplied folder, rather than from installed gems') do |path|
      $extensions_folder = path
    end
    
    opts.on('-r', '--reload', 'Reloads the server whenever any framework source files are modified') do
      $reload = true
    end

    opts.on('-h', '--help', 'Display this screen') do
      puts opts
      exit
    end
  end.parse!

  command = ARGV.shift


  case command
  when 'server'
    require '../requires'
    
    Yodel.config.extensions_folder = $extensions_folder if $extensions_folder
    Yodel.config.web_port = $web_port if $web_port
    
    if $env == 'production'
      Yodel.env.production!
    else
      Yodel.env.development!
    end
    
    if $reload
      require '../middleware/development_server'
      Rack::Server.start(app: DevelopmentServer.new, Port: Yodel.config.web_port)
    else
      require '../middleware/rack_server'
      require '../../yodel'
      Rack::Server.start(app: Application.new, Port: Yodel.config.web_port)
    end

  when 'dns'
    require '../requires'
    require './dns_server'
    DNSServer.start

  when 'console'
    require '../../yodel'
    require 'irb'
    
    Yodel.config.extensions_folder = $extensions_folder if $extensions_folder
    $application = Application.new
    IRB.start(__FILE__)

  when 'migrate'
    require '../../yodel'
    Yodel.config.extensions_folder = $extensions_folder if $extensions_folder
    $application = Application.new
    Migration.run_migrations_for_all_sites
  
  when 'deploy'
    require '../../yodel'
    Yodel.config.extensions_folder = $extensions_folder if $extensions_folder
    require './deploy'
    Deploy.new.deploy_site      

  when 'setup'
    require './installer'
    Installer.new.install_system_files
  
  when 'restart'
    require './restart'
    if Restart.can_restart?
      Restart.restart!
    else
      puts "Restart can only be run on OS X machines"
    end
    
  when 'update'
    require '../../yodel'
    require './restart'
    Yodel.config.extensions_folder = $extensions_folder if $extensions_folder
    $application = Application.new
    
    Migration.copy_missing_migrations_for_all_sites
    Migration.run_migrations_for_all_sites
    Restart.restart! if Restart.can_restart?
    
  else
    puts "Unknown command: #{command}"  
  end
end