Class: Colloquy::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/colloquy/runner.rb

Class Method Summary collapse

Class Method Details

.run!(argv) ⇒ Object

Much of this is borrowed verbatim from Goliath internals so we can use our own class structure



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
# File 'lib/colloquy/runner.rb', line 26

def run!(argv)
  options = {}
  goliath_argv = []

  option_parser = OptionParser.new do |opt|
    opt.banner = 'Usage: colloquy [options] /path/to/flow/root'
    
    opt.on('-a', '--address HOST', 'Hostname or IP address to bind to') do |host|
      goliath_argv << '-a' << host
    end
    
    opt.on('-p', '---port PORT', 'Port to run the server on') do |port|
      goliath_argv << '-p' << port
    end
    
    opt.on('-e', '---environment ENV', 'Rack environment to run the renderer') do |env|
      goliath_argv << '-e' << env
      options[:environment] = env
    end
    
    opt.on('-P', '--pidfile PATH_TO_FILE', 'Location to write the PID file to') do |pid_file|
      goliath_argv << '-P' << pid_file
    end
    
    opt.on('-d', '--daemonize', 'Daemonize the server') do
      goliath_argv << '-d'
    end
    
    opt.on('-v', '--verbose', 'Turn on debug logging') do
      goliath_argv << '-v'
      options[:verbose] = true
    end
    
    opt.on('-s', '--simulator', 'Run the flow simulator instead') do
      options[:interactive] = true
    end
    
    opt.on( '-h', '--help', 'Display this screen' ) do
      puts opt
      exit!
    end
  end
  
  option_parser.parse!(argv)
  
  path_root = argv.pop
  unless path_root
    puts 'You have to provide a flow root directory. See colloquy --help'
    exit!
  end
  
  goliath_argv << '-l' << Pathname.new(path_root).realpath.join('log', 'server.log').to_s
  
  if options[:interactive]
    simulator = Colloquy::Simulator.new(path_root: path_root, verbose: options[:verbose])
    simulator.run
  else      
    klass = Colloquy::Server
    api = klass.new(path_root: path_root, verbose: options[:verbose])
    runner = Goliath::Runner.new(goliath_argv, api)

    runner.app = Goliath::Rack::Builder.build(klass, api)
    runner.load_plugins(klass.plugins)
    runner.run
  end
end