Class: GroongaQueryLog::Command::FormatRegressionTestLogs

Inherits:
Object
  • Object
show all
Defined in:
lib/groonga-query-log/command/format-regression-test-logs.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ FormatRegressionTestLogs

Returns a new instance of FormatRegressionTestLogs.



31
32
33
# File 'lib/groonga-query-log/command/format-regression-test-logs.rb', line 31

def initialize(options={})
  @output = options[:output] || $stdout
end

Instance Method Details

#run(command_line) ⇒ Object



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
# File 'lib/groonga-query-log/command/format-regression-test-logs.rb', line 35

def run(command_line)
  parser = OptionParser.new
  parser.banner += " PATH1 PATH2 ..."
  parser.version = VERSION
  paths = parser.parse!(command_line)

  if paths.empty?
    format_log($stdin, "-")
  else
    paths.each do |path|
      if File.directory?(path)
        Find.find(path) do |sub_path|
          next unless File.file?(sub_path)
          File.open(sub_path) do |file|
            format_log(file, sub_path)
          end
        end
      else
        File.open(path) do |file|
          format_log(file, path)
        end
      end
    end
  end
  true
end