Class: Simon::OptionParser

Inherits:
Object
  • Object
show all
Defined in:
lib/simon/option_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parse_string) ⇒ OptionParser

Creates a new option parser with an array of arguments from the command line



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/simon/option_parser.rb', line 16

def initialize(parse_string)
  @option_hash = Trollop.options(parse_string) do
    banner Simon::BANNER
    opt :upload_limit,   "Limit upload speed (KB/s)",   :type => :int,
      :default => 0
    opt :download_limit, "Limit download speed (KB/s)", :type => :int,
      :default => 0
    opt :bind_part,      "Port to bind to",             :type => :int,
      :default => 6881
    opt :target,         "Directory to download to",    :type => :string,
      :default => "."
    opt :no_progress,    "Do not display the progress bar"
  end
  if parse_string.empty?
    raise Simon::NoFileError
  else
    @option_hash[:file] = parse_string.shift
  end
end

Instance Attribute Details

#option_hashObject (readonly)

Contains the hash of processed options



12
13
14
# File 'lib/simon/option_parser.rb', line 12

def option_hash
  @option_hash
end