Class: RubyWolf::CLI

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CLI

Returns a new instance of CLI.



7
8
9
10
11
# File 'lib/ruby_wolf/cli.rb', line 7

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

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



5
6
7
# File 'lib/ruby_wolf/cli.rb', line 5

def app
  @app
end

#configsObject (readonly)

Returns the value of attribute configs.



5
6
7
# File 'lib/ruby_wolf/cli.rb', line 5

def configs
  @configs
end

#serverObject (readonly)

Returns the value of attribute server.



5
6
7
# File 'lib/ruby_wolf/cli.rb', line 5

def server
  @server
end

Instance Method Details

#parse_optionsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ruby_wolf/cli.rb', line 21

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

#runObject



13
14
15
16
17
18
19
# File 'lib/ruby_wolf/cli.rb', line 13

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

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