# File lib/puma/control_cli.rb, line 16
    def initialize(argv, stdout=STDOUT, stderr=STDERR)
      @argv = argv
      @stdout = stdout
      @stderr = stderr
      @options = {}
      
      opts = OptionParser.new do |o|
        o.banner = "Usage: pumactl (-p PID | -P pidfile | -S status_file | -C url -T token) (#{COMMANDS.join("|")})"

        o.on "-S", "--state PATH", "Where the state file to use is" do |arg|
          @options[:status_path] = arg
        end

        o.on "-Q", "--quiet", "Not display messages" do |arg|
          @options[:quiet_flag] = true
        end

        o.on "-P", "--pidfile PATH", "Pid file" do |arg|
          @options[:pid_file] = arg
        end

        o.on "-p", "--pid PID", "Pid" do |arg|
          @options[:pid] = arg.to_i
        end

        o.on "-C", "--control-url URL", "The bind url to use for the control server" do |arg|
          @options[:control_url] = arg
        end

        o.on "-T", "--control-token TOKEN", "The token to use as authentication for the control server" do |arg|
          @options[:control_auth_token] = arg
        end

        o.on_tail("-H", "--help", "Show this message") do
          @stdout.puts o
          exit
        end

        o.on_tail("-V", "--version", "Show version") do
          puts Const::PUMA_VERSION
          exit
        end
      end

      opts.order!(argv) { |a| opts.terminate a }
      
      command = argv.shift
      @options[:command] = command if command

      # check present of command
      unless @options[:command]
        raise "Available commands: #{COMMANDS.join(", ")}"
      end

      unless COMMANDS.include? @options[:command]
        raise "Invalid command: #{@options[:command]}" 
      end

    rescue => e
      @stdout.puts e.message
      exit 1
    end