Sha256: 61d1605018f59987de24fbfb641bb2610fb8731f2a365c49bfcda78fd4031821

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

require 'optparse'

module RubyWolf
  class CLI
    attr_reader :app, :server, :configs

    def initialize(args)
      @args = args
      @configs = RubyWolf::Configuration.new
      @app_root = `pwd`.to_s.strip
    end

    def run
      parse_options
      raise 'Rack file not found' unless File.exist?(rack_file)

      @server = RubyWolf::Server.new(rack_file, configs)
      @server.start
    end

    def parse_options
      opt_parser = OptionParser.new do |opts|
        opts.banner = 'Usage: ruby_wolf [options]'

        opts.on('-d', '--daemon', 'Demonize this web server to run background') do
          @configs[:daemon] = true
        end

        opts.on('-h HOST', '--port=HOST', 'Binding host') do |arg|
          @configs[:host] = arg
        end

        opts.on('-p PORT', '--port=PORT', 'Port of the program') do |arg|
          @configs[:port] = arg.to_i
        end

        opts.on('-w WORKER', '--worker=WORKER', 'Number of worker processes') do |arg|
          @configs[:worker] = arg.to_i
        end

        opts.on('-h', '--help', 'Show the usages') do
          puts opts
          exit
        end
      end

      opt_parser.parse!(@args)
    end

    private

    def rack_file
      "#{@app_root}/config.ru"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ruby_wolf-0.3.0 lib/ruby_wolf/cli.rb
ruby_wolf-0.2.0 lib/ruby_wolf/cli.rb