Class: RSpec::Daemon::Cli

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

Constant Summary collapse

DEFAULT_OPTIONS =
{
  bind_address: "0.0.0.0",
  port: 3002,
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.startObject



11
12
13
# File 'lib/rspec/daemon/cli.rb', line 11

def self.start(...)
  new.start(...)
end

Instance Method Details

#start(argv) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rspec/daemon/cli.rb', line 15

def start(argv)
  options = DEFAULT_OPTIONS.dup
  if ENV['RSPEC_DAEMON_BIND_ADDRESS']
    options[:bind_address] = ENV['RSPEC_DAEMON_BIND_ADDRESS']
  end
  if ENV['RSPEC_DAEMON_PORT']
    options[:port] = ENV['RSPEC_DAEMON_PORT'].to_i
  end

  option_parser = OptionParser.new do |opts|
    opts.on('-v', '--version', 'Prints version') do
      puts RSpec::Daemon::VERSION
      exit
    end

    opts.on('-b', '--bind ADDRESS', 'address to bind (default: 0.0.0.0)') do |address|
      options[:bind_address] = address
    end

    opts.on('-p', '--port PORT', 'port to listen on (default: 3002)') do |port|
      options[:port] = port
    end
  end
  option_parser.parse!(argv)

  RSpec::Daemon.new(options[:bind_address], options[:port]).start
  0
end