Class: Specter::Cli

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

Constant Summary collapse

DEFAULT_HOST =
'0.0.0.0'
DEFAULT_PORT =
5028

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Cli

Returns a new instance of Cli.



13
14
15
16
# File 'lib/specter/cli.rb', line 13

def initialize(argv)
  @argv = argv
  @options = {}
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Class Method Details

.start(argv) ⇒ Object



18
19
20
# File 'lib/specter/cli.rb', line 18

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

Instance Method Details

#output_headerObject



22
23
24
25
26
27
# File 'lib/specter/cli.rb', line 22

def output_header
  puts "Booting Specter v#{VERSION}..."
  puts "* Running in #{RUBY_DESCRIPTION}"
  puts "* Listening on tcp://#{options[:host]}:#{options[:port]}"
  puts 'Use Ctrl-C to stop'
end

#runObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/specter/cli.rb', line 29

def run
  parse_options
  output_header

  @thread = @server.run
  @thread.run

  Signal.trap('INT') do
    puts 'Stopping...'
    @thread.exit
    exit
  end

  @thread.join
end