Sha256: 5ee36313d60d6479bce87d64f2115181938413bc217ae4bdc6bcbad5e91574e6

Contents?: true

Size: 1.26 KB

Versions: 5

Compression:

Stored size: 1.26 KB

Contents

require 'reel/rack'
require 'optparse'

module Reel
  module Rack
    class CLI
      def initialize(argv)
        @argv   = argv
        @options = {
          addr:   "localhost",
          Port:   3000,
          quiet:  false,
          rackup: "config.ru"
        }
        parser
      end

      def parser
        @parser ||= OptionParser.new do |o|
          o.banner = "reel-rack <options> <rackup file>"

          o.on "-a", "--addr ADDR", "Address to listen on (default #{@options[:addr]})" do |addr|
            @options[:addr] = addr
          end

          o.on "-p", "--port PORT", "Port to bind to (default #{@options[:Port]})" do |port|
            @options[:Port] = port
          end

          o.on "-q", "--quiet", "Suppress normal logging output" do
            @options[:quiet] = true
          end

          o.on_tail "-h", "--help", "Show help" do
            STDOUT.puts @parser
            exit 1
          end
        end
      end

      def run
        @parser.parse! @argv
        @options[:rackup] = @argv.shift if @argv.last

        app, options = ::Rack::Builder.parse_file(@options[:rackup])
        options.merge!(@options)
        ::Rack::Handler::Reel.run(app, options)

        Celluloid.logger.info "That's all, folks!"
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
reel-rack-0.2.3 lib/reel/rack/cli.rb
reel-rack-0.2.2 lib/reel/rack/cli.rb
reel-rack-0.2.1 lib/reel/rack/cli.rb
reel-rack-0.2.0 lib/reel/rack/cli.rb
reel-rack-0.1.0 lib/reel/rack/cli.rb