Skip to content

Commit

Permalink
extractor: add support for log input via stdin
Browse files Browse the repository at this point in the history
Now Extractor#run finishes just when no pipe, redirect, or any input file,
but is it overspec? Extractor#run should wait inputting for stdin?
  • Loading branch information
Haruka Yoshihara committed Dec 17, 2012
1 parent ff43891 commit 385e857
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/groonga/query-log/extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,20 @@ def initialize
end

def run(*arguments)
log = ""
begin
log_paths = @option_parser.parse!(arguments)
rescue OptionParser::ParseError
raise(ArgumentError, $!.message)
end

if log_paths.empty?
raise(NoInputError, "Error: Please specify input log files.")
unless log_via_stdin?
raise(NoInputError, "Error: Please specify input log files.")
end
log = ARGF
end

log = ""
log_paths.each do |log_path|
log << File.read(log_path)
end
Expand Down Expand Up @@ -154,6 +157,18 @@ def target?(command)

true
end

def log_via_stdin?
input_with_pipe? or input_with_redirect?
end

def input_with_pipe?
File.pipe?($stdin)
end

def input_with_redirect?
not File.select([$stdin], [], [], 0).nil?
end
end
end
end

0 comments on commit 385e857

Please sign in to comment.