Class: LIS::Options

Inherits:
Hash
  • Object
show all
Defined in:
lib/lis/commands/application.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Options) initialize(args)

A new instance of Options



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
# File 'lib/lis/commands/application.rb', line 7

def initialize(args)
  super()

  default_options = { :port => "/dev/ttyUSB0", :uri => "http://localhost/lis/" }
  self.merge!(default_options)

  @opts = OptionParser.new do |o|
    appname = File.basename($0)
    o.banner = "Usage: #{appname} [options]"

    o.on('-l, --listen PORT', 'which port to listen on (default: "/dev/ttyUSB0")') do |port|
      self[:port] = port
    end
    o.on('-e, --endpoint URI', 'HTTP endpoint (default: "http://localhost/lis/")') do |endpoint|
      self[:uri] = endpoint
    end
    o.on("-v", "--[no-]verbose", "Run verbosely") do |v|
      $VERBOSE = v
      self[:verbose] = v
    end
  end

  begin
    @opts.parse!(args)
    self[:project_name] = args.shift
  rescue OptionParser::ParseError => e
    self[:invalid_argument] = e.message
  end
end

Instance Attribute Details

- (Object) opts (readonly)

Returns the value of attribute opts



5
6
7
# File 'lib/lis/commands/application.rb', line 5

def opts
  @opts
end