Class: Urltest::Commands::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/urltest/commands/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Options

Returns a new instance of Options.



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
# File 'lib/urltest/commands/options.rb', line 9

def initialize(args)
  @options = OpenStruct.new
  @options.times = 10

  opts = OptionParser.new do |opts|
    opts.banner = "\nSpeed test for your url(api)\n\nUsage: urltest [options]"
    opts.version = Urltest::VERSION

    opts.separator ''
    opts.separator 'Optional:'

    opts.on_head('-t', '--times [N]', Integer, 'Request times') do |t|
      @options.times = t || 10
    end
    opts.on_head('-l', '--link [URL]', String, 'URL link') do |l|
      @options.link = l
    end

    opts.on('--version', "Show version") do |v|
      puts opts.version
      exit
    end

    opts.on('--help', "Show help") do |v|
      puts opts
      exit
    end
  end

  opts.parse!(args)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/urltest/commands/options.rb', line 7

def options
  @options
end

Instance Method Details

#parseObject



41
42
43
# File 'lib/urltest/commands/options.rb', line 41

def parse
  @options
end