Class: Webmeter::CLI

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ CLI

Returns a new instance of CLI.



12
13
14
15
# File 'lib/webmeter/cli.rb', line 12

def initialize(options)
  @options = options
  execute
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/webmeter/cli.rb', line 6

def options
  @options
end

Class Method Details

.execute(options = nil) ⇒ Object



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

def self.execute(options = nil)
  new(options || ARGV)
end

Instance Method Details

#executeObject



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
43
# File 'lib/webmeter/cli.rb', line 17

def execute
  params = {}
  optparse = OptionParser.new do |opts|
    opts.on('-h', '--help', 'Display this screen') do
      puts opts
      exit
    end
    params[:address] = "www.example.com"
    opts.on('-a', '--address <domain>', String, 'Website address') do |address|
      params[:address] = address
    end
    params[:workers] = 1
    opts.on('-w', '--workers <number>', Integer, 'Number of workers') do |workers|
      params[:workers] = workers
    end
    params[:file] = "access.log"
    opts.on('-f', '--file <path>', String, 'Log file') do |file|
      params[:file] = file
    end
    params[:limit] = nil
    opts.on('-l', '--limit <number>', Integer, 'Limit requests') do |limit|
      params[:limit] = limit
    end
  end
  optparse.parse!
  Benchmark.bench(params)
end