Class: Webload::Client::WebloadOptionParser

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

Class Method Summary collapse

Class Method Details

.parse(args) ⇒ Object



6
7
8
9
10
11
12
13
14
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
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/webload/client/cli.rb', line 6

def self.parse(args)
  options = OpenStruct.new

  parser = OptionParser.new do |opts|
    opts.banner = "Usage: webload [options]"

    opts.on("-q", "--queue-name SQS_QUEUE_NAME", "The sqs queue name") do |v|
      options.queue_name = v
    end

    opts.on("-l", "--log-file LOG_FILE", "The log file to be processed") do |v|
      options.log_file = v
    end

    opts.on("-r", "--rate-per-minute RATE", "The number of requests per minute") do |v|
      options.rpm = v.to_i
    end

    opts.on("-u", "--url URL", "The destination URL to send the traffic to") do |v|
      options.url = v
    end

    opts.on("-b", "--batch NUM", "The number of requests to accumulate before sending to sqs") do |v|
      options.batch = v.to_i
    end

    opts.on("-i", "--ignore IGNORE", "a CSV list of patterns to ignore") do |v|
      options.ignore = v.split(',')
    end

    opts.separator ""

    opts.on_tail("-v", "--verbose", "Run verbosely") do |v|
      options.verbose = v
    end

    opts.on_tail("-h", "--help", "Show this message") do
      puts opts
      exit
    end
  end
  
  # Default values
  options.rpm ||= 0
  options.batch ||= 1

  # Parse and return options
  parser.parse!(args)
  options
end