Class: TorqBox::CLI

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



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
55
56
57
58
59
60
61
# File 'lib/torqbox/cli.rb', line 24

def initialize(argv)
  @boot_options = {}
  @app_options = {}
  ENV['RACK_ENV'] = ENV['RAILS_ENV'] = 'development'
  OptionParser.new do |opts|
    opts.banner = 'Usage: torqbox [options] [rackup file]'

    opts.on '-b', '--bind-address IP', 'IP or host to bind to' do |arg|
      @boot_options[:host] = arg
    end
    opts.on '--dir DIR', 'Change directory before starting' do |arg|
      @boot_options[:root] = arg
    end
    opts.on '-E', '--env ENVIRONMENT', 'Environment to run under (default: development)' do |arg|
      ENV['RACK_ENV'] = ENV['RAILS_ENV'] = arg
    end
    opts.on '-p', '--port PORT', 'HTTP port to listen on' do |arg|
      @boot_options[:port] = arg
    end
    opts.on '-q', '--quiet', 'Only write errors to the output' do
      @boot_options[:log_level] = 'ERROR'
    end
    opts.on_tail('-h', '--help', 'Show this message') do
      puts opts
      exit 1
    end
    opts.on_tail('--version', 'Show version') do
      puts "TorqBox #{TorqBox::VERSION}"
      exit 1
    end
  end.parse!(argv)

  unless argv.empty?
    @app_options[:rackup] = argv.shift
  end

  @server = ::TorqBox::Server.new(@boot_options)
end

Instance Attribute Details

#serverObject (readonly)

Returns the value of attribute server.



22
23
24
# File 'lib/torqbox/cli.rb', line 22

def server
  @server
end

Instance Method Details

#startObject



63
64
65
# File 'lib/torqbox/cli.rb', line 63

def start
  @server.start(@app_options)
end

#stopObject



67
68
69
# File 'lib/torqbox/cli.rb', line 67

def stop
  @server.stop
end