Class: RubyWolf::CLI
- Inherits:
-
Object
- Object
- RubyWolf::CLI
- Defined in:
- lib/ruby_wolf/cli.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#configs ⇒ Object
readonly
Returns the value of attribute configs.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Instance Method Summary collapse
-
#initialize(args) ⇒ CLI
constructor
A new instance of CLI.
- #parse_options ⇒ Object
- #run ⇒ Object
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
#app ⇒ Object (readonly)
Returns the value of attribute app.
5 6 7 |
# File 'lib/ruby_wolf/cli.rb', line 5 def app @app end |
#configs ⇒ Object (readonly)
Returns the value of attribute configs.
5 6 7 |
# File 'lib/ruby_wolf/cli.rb', line 5 def configs @configs end |
#server ⇒ Object (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_options ⇒ Object
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 49 50 51 52 53 54 |
# File 'lib/ruby_wolf/cli.rb', line 23 def opt_parser = OptionParser.new do |opts| opts. = '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('-e ENVIRONMENT', '--environment=ENVIRONMENT', 'Current environment') do |arg| @configs[:environment] = arg end opts.on('-h', '--help', 'Show the usages') do puts opts exit end end opt_parser.parse!(@args) end |
#run ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/ruby_wolf/cli.rb', line 13 def run set_environment raise 'Rack file not found' unless File.exist?(rack_file) @server = RubyWolf::Server.new(rack_file, configs) @server.start end |