Class: Bake::BakeRtextServiceOptions

Inherits:
Parser
  • Object
show all
Defined in:
lib/rtext-service/options/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Parser

#add_option, #get_block, #num_parameter?, #parse_internal, #valid?

Constructor Details

#initialize(argv) ⇒ BakeRtextServiceOptions



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rtext-service/options/options.rb', line 10

def initialize(argv)
  super(argv)

  @loglevel = 'info'
  @patterns = []
  @timeout = 3600

  add_option([""                 ], lambda { |x| @patterns.push(x)                                    })
  add_option(["-l", "--loglevel" ], lambda { |x| set_loglevel(x)                                      })
  add_option(["-t", "--timeout"  ], lambda { |x| @timeout = x.to_i                                    })
  add_option(["-h", "--help"     ], lambda { usage; ExitHelper.exit(0)                                })
  add_option(["--version"        ], lambda { Bake::Version.printBakeFormatVersion; ExitHelper.exit(0) })
end

Instance Attribute Details

#loglevelObject (readonly)

String



6
7
8
# File 'lib/rtext-service/options/options.rb', line 6

def loglevel
  @loglevel
end

#patternsObject (readonly)

Returns the value of attribute patterns.



7
8
9
# File 'lib/rtext-service/options/options.rb', line 7

def patterns
  @patterns
end

#timeoutObject (readonly)

Number



8
9
10
# File 'lib/rtext-service/options/options.rb', line 8

def timeout
  @timeout
end

Instance Method Details

#parse_optionsObject



33
34
35
36
# File 'lib/rtext-service/options/options.rb', line 33

def parse_options()
  parse_internal(true)
  @patterns = ['./**'] unless @patterns.any?
end

#usageObject



24
25
26
27
28
29
30
31
# File 'lib/rtext-service/options/options.rb', line 24

def usage
  puts [
    "Usage: #{__FILE__} [options] <dir patterns>",
    "  -l, --loglevel [string], log level is one of [debug, info, warn, error, fatal].",
    "  -t, --timeout [number], idle timeout in seconds after which the service will shutdown. Default is 3600.",
    "  dir patterns, glob patterns."
  ].join("\n")
end