Class: TestServer::Cli::Main

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

Instance Method Summary collapse

Instance Method Details

#initObject



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
# File 'lib/test_server/cli/main.rb', line 70

def init
  TestServer.config = TestServer::Config.new(options[:config_file]) if options[:config_file]

  TestServer.config.log_level             = options[:log_level]              if options[:log_level]
  TestServer.config.debug_mode            = options[:debug_mode]             if options[:debug_mode]
  TestServer.config.pid_file              = options[:pid_file]               if options[:pid_file]
  TestServer.config.access_log            = options[:access_log]             if options[:access_log]
  TestServer.config.sass_cache            = options[:sass_cache]             if options[:sass_cache]
  TestServer.config.reload_config_signal  = options[:reload_config_signal]   if options[:reload_config_signal]
  TestServer.config.log_level             = options[:log_level]              if options[:log_level]
  TestServer.config.listen                = options[:listen]                 if options[:listen]
  TestServer.config.environment           = options[:environment]            if options[:environment]

  TestServer.config.lock

  TestServer.ui_logger.level = TestServer.config.log_level
  TestServer.enable_debug_mode if TestServer.config.debug_mode

  TestServer.ui_logger.debug('Options: ' + options.to_s)
  TestServer.ui_logger.debug("Config:\n" + TestServer.config.to_s)

  Actions::InitializeApplication.new(
    force: options[:force], 
    pre_seed: options[:pre_seed],
    create_pid_directory: options[:create_pid_directory],
    create_log_directory: options[:create_log_directory],
    create_sass_cache: options[:create_sass_cache],
    create_config_file: options[:create_config_file],
    create_secrets_file: options[:create_secrets_file],
  ).run
end

#serveObject



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
# File 'lib/test_server/cli/main.rb', line 15

def serve
  TestServer.config = TestServer::Config.new(options[:config_file]) if options[:config_file]
  TestServer.config.access_log = options[:access_log] if options[:access_log]
  TestServer.config.log_level = options[:log_level] if options[:log_level]
  TestServer.config.debug_mode = options[:debug_mode] if options[:debug_mode]
  TestServer.config.environment = options[:environment] if options[:environment]
  TestServer.config.worker_count = options[:worker_count] if options[:worker_count]
  TestServer.config.listen = options[:listen] if options[:listen]
  TestServer.config.lock

  TestServer.ui_logger.level = TestServer.config.log_level
  TestServer.enable_debug_mode if TestServer.config.debug_mode

  TestServer.ui_logger.debug('Options: ' + options.to_s)
  TestServer.ui_logger.debug("Config:\n" + TestServer.config.to_s)

  command_klass = case options[:with].to_sym
           when :puma
             ServerCommands::Puma
           when :rackup
             ServerCommands::Rackup
           else
             ServerCommands::Rackup
           end

  command = command_klass.new(
    listen: TestServer.config.listen,
    environment: TestServer.config.environment,
    worker_count: TestServer.config.worker_count,
  )

  ENV['DEBUG']      = TestServer.config.debug_mode.to_s if TestServer.config.debug_mode
  ENV['ACCESS_LOG'] = TestServer.config.access_log.to_s if TestServer.config.access_log
  ENV['LOG_LEVEL']  = TestServer.config.log_level.to_s  if TestServer.config.log_level

  Server.new(command).start
end