Class: Puma::CLI

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

Overview

Handles invoke a Puma::Server in a command line style.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv, log_writer = LogWriter.stdio, events = Events.new, env: ENV) ⇒ CLI

Create a new CLI object using argv as the command line arguments.



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

def initialize(argv, log_writer = LogWriter.stdio, events = Events.new, env: ENV)
  @debug = false
  @argv = argv.dup
  @log_writer = log_writer
  @events = events

  @conf = nil

  @stdout = nil
  @stderr = nil
  @append = false

  @control_url = nil
  @control_options = {}

  begin
    setup_options env

    if file = @argv.shift
      @conf.configure do |user_config, file_config|
        file_config.rackup file
      end
    end
  rescue UnsupportedOption
    exit 1
  end

  @conf.configure do |user_config, file_config|
    if @stdout || @stderr
      user_config.stdout_redirect @stdout, @stderr, @append
    end

    if @control_url
      user_config.activate_control_app @control_url, @control_options
    end
  end

  @launcher = Puma::Launcher.new(@conf, env: ENV, log_writer: @log_writer, events: @events, argv: argv)
end

Instance Attribute Details

#launcherObject (readonly)

Returns the value of attribute launcher.



67
68
69
# File 'lib/puma/cli.rb', line 67

def launcher
  @launcher
end

Instance Method Details

#runObject

Parse the options, load the rackup, start the server and wait for it to finish.



72
73
74
# File 'lib/puma/cli.rb', line 72

def run
  @launcher.run
end