Class: Fwd::CLI

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



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

def initialize(argv)
  super()
  parser.parse!(argv)
  @core = Fwd.new(self)
end

Instance Attribute Details

#coreObject (readonly)

Returns the value of attribute core.



10
11
12
# File 'lib/fwd/cli.rb', line 10

def core
  @core
end

Class Method Details

.run!(argv = ARGV) ⇒ Object



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

def self.run!(argv = ARGV)
  new(argv).run!
end

Instance Method Details

#parserObject



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
56
57
58
59
60
61
62
63
64
65
# File 'lib/fwd/cli.rb', line 22

def parser
  @parser ||= OptionParser.new do |o|
    o.banner = "Usage: fwd-rb [options]"
    o.separator ""

    o.on("-B", "--bind URI", "Listen on this address. Default: tcp://0.0.0.0:7289") do |uri|
      update bind: URI.parse(uri).to_s
    end

    o.on("-F", "--forward U1,[..,Un]", Array, "Forward to these URIs") do |uris|
      update forward: uris.map {|uri| URI.parse(uri).to_s }
    end

    o.on("-f", "--flush M:N",
      "Flush after an interval of N seconds, " <<
      "or after receiving M messages, " <<
      "Default: 10000:60") do |values|
      m,n = values.split(":").map(&:to_i)
      update flush_rate: m.to_i, flush_interval: n.to_i
    end

    o.on("--path PATH", "Root path for storage. Default: ./tmp") do |path|
      update path: path
    end

    o.on("--prefix STRING", "Custom prefix for buffer files. Default: buffer") do |prefix|
      update prefix: prefix
    end

    o.on("-l", "--log PATH", "Custom log path. Default: STDOUT") do |path|
      update log: path
    end

    o.on("-v", "--verbose", "Enable verbose logging.") do
      update log_level: ::Logger::DEBUG
    end

    o.separator ""
    o.on_tail("-h", "--help", "Show this message") do
      puts o
      exit
    end
  end
end

#run!Object



18
19
20
# File 'lib/fwd/cli.rb', line 18

def run!
  @core.run!
end