Class: LogTwuncator::Options

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

Class Method Summary collapse

Class Method Details

.parse(args = ARGV, validate = true) ⇒ Object



6
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
# File 'lib/log_twuncator/options.rb', line 6

def self.parse(args = ARGV, validate = true)
  options = {}
  options[:delay] = 5      
  opts = OptionParser.new do |opts|
    opts.banner = "Usage: log_twuncator_daemon.rb [options]"
    opts.separator ""
    opts.separator "Specific options:"        
    
    opts.on("-d", "--delay N", Integer, "Check files for truncation every N minutes (default: 5)") do |v|
      options[:delay] = v
    end
  
    opts.on("-c", "--config FILE", String, "Config file with projects session files to check") do |v|
      options[:config] = v
    end
    
    opts.on("-l", "--log FILE", String, "Log file for truncator") do |v|
      options[:log] = v
    end
          
    opts.on_tail("-h", "--help", "Show this message") do
      puts opts
      exit
    end
  end
  opts.parse!(args)
  validate_options(options) if validate
  options
end

.validate_options(options) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/log_twuncator/options.rb', line 36

def self.validate_options(options)
  unless options[:delay]
    puts "Delay in seconds required [-d N]"
    exit
  end
  unless options[:config]
    puts "Config file required [-c FILE]"
    exit
  end
end