Class: YourKarma::CLI

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

Defined Under Namespace

Classes: ArgumentParser, Reporter

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CLI

Returns a new instance of CLI.



19
20
21
# File 'lib/yourkarma/cli.rb', line 19

def initialize(options = {})
  self.options = options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/yourkarma/cli.rb', line 8

def options
  @options
end

Class Method Details

.run(io, arguments) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/yourkarma/cli.rb', line 10

def self.run(io, arguments)
  options = { io: io }
  options.merge! ArgumentParser.new.parse(arguments)
  self.new(options).run
rescue ArgumentParser::InvalidOption => e
  options[:io].puts e
  1
end

Instance Method Details

#runObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/yourkarma/cli.rb', line 23

def run
  client      = Client.new(options)
  benchmarker = Benchmarker.new(options)
  reporter    = Reporter.new(options)
  reporter.report_header
  iterations = options[:iterations] || Float::INFINITY
  code = 1
  (1..iterations).each do
    begin
      code = run_once(client, benchmarker, reporter)
    rescue Interrupt
      break
    end
  end
  reporter.report_quit(code)
end