[Groonga-commit] groonga/groonga-query-log [master] extractor: add support for log input via stdin

Zurück zum Archiv-Index

Haruka Yoshihara null+****@clear*****
Mon Dec 17 17:47:39 JST 2012


Haruka Yoshihara	2012-12-17 17:47:39 +0900 (Mon, 17 Dec 2012)

  New Revision: 385e8578b65b16af2dc0064817b67bebd81ccabe
  https://github.com/groonga/groonga-query-log/commit/385e8578b65b16af2dc0064817b67bebd81ccabe

  Log:
    extractor: add support for log input via stdin
    
    Now Extractor#run finishes just when no pipe, redirect, or any input file,
    but is it overspec? Extractor#run should wait inputting for stdin?

  Modified files:
    lib/groonga/query-log/extractor.rb

  Modified: lib/groonga/query-log/extractor.rb (+17 -2)
===================================================================
--- lib/groonga/query-log/extractor.rb    2012-12-17 17:05:06 +0900 (b5e5c88)
+++ lib/groonga/query-log/extractor.rb    2012-12-17 17:47:39 +0900 (84f877e)
@@ -42,6 +42,7 @@ module Groonga
       end
 
       def run(*arguments)
+        log = ""
         begin
           log_paths = @option_parser.parse!(arguments)
         rescue OptionParser::ParseError
@@ -49,10 +50,12 @@ module Groonga
         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
@@ -154,6 +157,18 @@ module Groonga
 
         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
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Zurück zum Archiv-Index