class Puma::ControlCLI
def initialize(argv, stdout=STDOUT, stderr=STDERR, env: ENV)
def initialize(argv, stdout=STDOUT, stderr=STDERR, env: ENV) @state = nil @quiet = false @pidfile = nil @pid = nil @control_url = nil @control_auth_token = nil @config_file = nil @command = nil @environment = env['APP_ENV'] || env['RACK_ENV'] || env['RAILS_ENV'] @argv = argv.dup @stdout = stdout @stderr = stderr @cli_options = {} opts = OptionParser.new do |o| o.banner = "Usage: pumactl (-p PID | -P pidfile | -S status_file | -C url -T token | -F config.rb) (#{CMD_PATH_SIG_MAP.keys.join("|")})" o.on "-S", "--state PATH", "Where the state file to use is" do |arg| @state = arg end o.on "-Q", "--quiet", "Do not display messages" do |arg| @quiet = true end o.on "-P", "--pidfile PATH", "Pid file" do |arg| @pidfile = arg end o.on "-p", "--pid PID", "Pid" do |arg| @pid = arg.to_i end o.on "-C", "--control-url URL", "The bind url to use for the control server" do |arg| @control_url = arg end o.on "-T", "--control-token TOKEN", "The token to use as authentication for the control server" do |arg| @control_auth_token = arg end o.on "-F", "--config-file PATH", "Puma config script" do |arg| @config_file = arg end o.on "-e", "--environment ENVIRONMENT", "The environment to run the Rack app on (default development)" do |arg| @environment = arg end o.on_tail("-H", "--help", "Show this message") do @stdout.puts o exit end o.on_tail("-V", "--version", "Show version") do @stdout.puts Const::PUMA_VERSION exit end end opts.order!(argv) { |a| opts.terminate a } opts.parse! @command = argv.shift # check presence of command unless @command raise "Available commands: #{CMD_PATH_SIG_MAP.keys.join(", ")}" end unless CMD_PATH_SIG_MAP.key? @command raise "Invalid command: #{@command}" end unless @config_file == '-' environment = @environment || 'development' if @config_file.nil? @config_file = %W(config/puma/#{environment}.rb config/puma.rb).find do |f| File.exist?(f) end end if @config_file require_relative 'configuration' require_relative 'log_writer' config = Puma::Configuration.new({ config_files: [@config_file] }, {} , env) config.load @state ||= config.options[:state] @control_url ||= config.options[:control_url] @control_auth_token ||= config.options[:control_auth_token] @pidfile ||= config.options[:pidfile] end end rescue => e @stdout.puts e.message exit 1 end